我的一個ListPicker中有一個SelectionChanged事件在我的一個應用程序頁面中,在加載頁面之前觸發多次。這對我來說真的很不方便,因爲當選擇某個項目時,會顯示一個MessageBox(並執行其他操作)。每當頁面導航到時,MessageBox顯示兩次。我怎樣才能解決這個問題?ListPicker SelectionChanged在導航過程中被稱爲多次的事件
XAML
<toolkit:ListPicker x:Name="ThemeListPicker" Header="Theme"
ItemTemplate="{StaticResource PickerItemTemplate}"
SelectionChanged="ThemeListPicker_SelectionChanged"/>
XAML.CS
private void ThemeListPicker_SelectionChanged(object sender,
SelectionChangedEventArgs e)
{
if(ThemeListPicker.SelectedIndex != -1)
{
var theme = (sender as ListPicker).SelectedItem;
if (index == 0)
{
Settings.LightTheme.Value = true;
MessageBox.Show("light");
}
else
{
Settings.LightTheme.Value = false;
MessageBox.Show("dark");
}
}
}
如何從stk_Tap事件中獲取在ListPicker中選擇的項目? – Matthew