I am using Listview with an observable collection.
But I am getting weird behaviour when I am going from Navigation Page A -> B -> C -> B
Page B listview datetemplate
DATATEMPLATE
<\ListView.ItemTemplate>
<\DataTemplate>
<\ViewCell>
<\StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand">
<\Label x:Name="Color" BackgroundColor="{Binding ListViewColor}" HorizontalOptions="Start" WidthRequest="10" VerticalOptions="FillAndExpand" Margin="0,3,0,3"/>
<\StackLayout Orientation="Vertical" HorizontalOptions="StartAndExpand">
<\Label x:Name="Title" Text="{Binding ListViewTitle}"/>
<\Label x:Name="GoodsKind" Text="{Binding ListViewGoodsKind}" />
<\Label x:Name="Treatment" Text="{Binding ListViewTreatment}" />
<//StackLayout>
<\Switch x:Name="Switch" IsToggled="{Binding ListViewChecked, Mode=TwoWay}" Toggled="Switch_Toggled" HorizontalOptions="End" />
<//StackLayout>
<//ViewCell>
<//DataTemplate>
<//ListView.ItemTemplate>
PAGE B model from data template
public bool ListViewChecked
{
get
{
return _Checked;
}
set
{
if (this._Checked == value)
{
return;
}
_Checked = value;
if (PropertyChanged != null)
{
OnPropertyChanged(nameof(ListViewChecked));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
this.PropertyChanged?.Invoke(this,
new PropertyChangedEventArgs(propertyName));
}
Step B
On listview, ItemSelected page C is loaded
but before the Listview Item Selected event is fired the child event is fired
case Switch IsToggled=True
Switch_Toggled is fired before Item Selected event is fired.
case Switch IsToggled=False
switch_toggled is not fired only Item Selected event is fired.
STEP B -> C -> B
I navigate from page B to page C and then back to Page B
case When I click on Switch to enable/disable
Switch IsToggled event is fired three times
Repeat the step B-> C -> B
Switch IsToggled event is fired four times
,............................. and so on
Is this some kind of bug in Listview or am I doing something wrong with my code?