rams
rams

Reputation: 6791

How to programmatically remove content from Xamarin.Forms ScrollView?

On a content page I have a scrollview into which from code-behind I add a grid and content to the grid. I want to remove the previously added content on tap of a button and add new content.

<ScrollView Grid.Row="3" x:Name="frequencyView">
</ScrollView>

In code behind I have

var grid = new Grid();
grid.Rowdefinitions.Add(...)
grid.Children.Add(.. another view..)
frequencyView.Content = grid;

However even if I run

grid.children.clear() the previously added content is not removed from the view. I have tried Page.ForceLayout() and frequencyView.ForceLayout() after removing the children from the grid. Setting frequencyView.Content = null has no effect.

How do I remove previously added content from the scrollview?

Upvotes: 0

Views: 1251

Answers (1)

Alessandro Caliaro
Alessandro Caliaro

Reputation: 5768

Usually you should not remove UI objects from your layout. You should create your layout then hide / show controls...

Upvotes: 1

Related Questions