I made two list views in the XAML called CreateOperator.
I have an button to create new gadgets within the same page but that directs you to another page to create them. Once you create the gadgets, you can go back to CreateOperator by hitting the back button.
To refresh the ListViews when the CreateOperator view is back in focus I use OnAppearing to Initilize the components of the view.
protected override void OnAppearing()
{
//base.OnAppearing();
// Do something here when the page is in focus
InitializeComponent();
}
This code works and it does refresh the ListView with the new gadgets.
But when I select and item from the ListView, the SelectedItem returns null.
The only way to not get SelectedItem as null is to back out of the view and then come back in the view. But that defeats the whole purpose of using OnAppearing which was to not have to back out of the view.
Any help would be appreciated.
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding Name}" />
<Label Text="{Binding Description}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView x:Name="operatorGadgetsListView2" ItemSelected="ListViewSelectionChanged" ItemsSource="{x:Static local:ListHolder.GadgetList}" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding Name}" />
<Label Text="{Binding Description}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
For some reason I had to change the ListView to null before updating it again.
The resulting code looks like this :