我有一个带有 SelectionChanged 事件的 ListPicker。显然,我希望 SelectionChange 事件仅在我更改选择时触发,但在我的情况下,它也会在我加载页面时触发。
代码:
<toolkit:ListPicker x:Name="sightingTypesPicker" ItemsSource="{Binding sightingTypes, ElementName=this}" SelectionChanged="sightingTypesPicker_SelectionChanged">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" FontSize="{StaticResource PhoneFontSizeSmall}"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" FontSize="{StaticResource PhoneFontSizeLarge}"/>
<TextBlock Visibility="Collapsed" Text="{Binding TypeId}" FontSize="{StaticResource PhoneFontSizeSmall}"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
C#:
private void sightingTypesPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SightingType selecteditem = e.AddedItems[0] as SightingType;
Sighting.Instance.TypeId = selecteditem.TypeID;
}