Skip to content

[Windows, Android] ScrollView Content Not Removed When Set to Null #33067

@devanathan-vaithiyanathan

Description

Description

When setting ScrollView.Content = null in .NET MAUI, the previous content is not removed on Android and Windows platforms. As a result, the old view remains in the UI.

Steps to Reproduce

public partial class MainPage : ContentPage {	ScrollView _scrollView = null!;	Label _originalContent = null!;	Button _setNullButton = null!;	public MainPage()	{	CreateUI();	}	void CreateUI()	{	_originalContent = new Label	{	Text = "This is a sample label inside the ScrollView that can be set to null and added back.",	Padding = new Thickness(20),	AutomationId = "ContentLabel",	FontSize = 16	};	_scrollView = new ScrollView	{	BackgroundColor = Colors.LightGray,	HeightRequest = 300,	Content = _originalContent	};	_setNullButton = new Button	{	Text = "Set Content to Null",	AutomationId = "SetNullButton"	};	_setNullButton.Clicked += OnSetContentNullClicked;	var layout = new VerticalStackLayout	{	Spacing = 20,	Padding = new Thickness(30),	Children = { _setNullButton, _scrollView }	};	Content = layout;	}	void OnSetContentNullClicked(object? sender, EventArgs e)	{	_scrollView.Content = null;	}	void OnAddContentClicked(object sender, EventArgs e)	{	if (_originalContent != null)	{	_scrollView.Content = _originalContent;	}	} } 

1.Paste the above code in MainPage.xaml.cs
2.Click the Set Content to Null button.
3. Observe the behavior in Windows and Android.

Expected Behavior
When ScrollView.Content is set to null, the ScrollView should remove the existing content and appear empty on all platforms.

Actual Behavior
The previous content is not removed. Old UI elements remain inside the ScrollView.

Link to public reproduction project repository

No response

Version with bug

10.0.11

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Windows, Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions