【发布时间】:2017-09-05 02:30:20
【问题描述】:
我的一个应用程序页面中的 ListPicker 中有一个 SelectionChanged 事件,该事件在页面加载之前触发了多次。 This is really inconvenient for me as when an item is selected, a MessageBox is displayed (and other actions will be performed).每次页面为 NavigatedTo 时,MessageBox 会显示两次。我该如何解决这个问题?
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");
}
}
}
【问题讨论】:
标签: c# xaml windows-phone-7 windows-phone-8 listpicker