Windows Phone 8.1组合框点击事件don';不起作用
本文关键字:don 事件 不起作用 Phone 组合 Windows | 更新日期: 2023-09-27 18:27:56
你能解释一下为什么我的组合框中的Tapped事件没有引发指定的方法吗?
<ComboBox HorizontalAlignment="Center" Margin="19,9.5,19,9.5" Header="Choose the type of the plot" FontSize="15">
<ComboBoxItem Content="Signal Winner" Tapped="Winner_Signal_Tapped" />
<ComboBoxItem Content="Filtered signal Winner" Tapped="Winner_Prediction_Tapped" />
<ComboBoxItem Content="Quality Winner" Tapped="Winner_Quality_Tapped" />
<ComboBoxItem Content="Error Winner" Tapped="Winner_Error_Tapped" />
<ComboBoxItem Content="Signal LMS" Tapped="LMS_Signal_Tapped" />
<ComboBoxItem Content="Filtered signal LMS" Tapped="LMS_Prediction_Tapped" />
<ComboBoxItem Content="Quality LMS" Tapped="LMS_Quality_Tapped" />
<ComboBoxItem Content="Error LMS" Tapped="LMS_Error_Tapped" />
</ComboBox>
private void plotButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (LMSPlot != null)
{
graphGrid.Visibility = Windows.UI.Xaml.Visibility.Visible;
var line1 = plot1.Series[0] as LineSeries;
line1.ItemsSource = LMSPlot;
}
if (WinnerPlot != null)
{
graphGrid.Visibility = Windows.UI.Xaml.Visibility.Visible;
var line1 = plot1.Series[0] as LineSeries;
line1.ItemsSource = WinnerPlot;
}
}
catch(Exception ex)
{
//for debug purpose
}
}
附言:我指出,如果我在ComboBox中只保留4个项目,Tapped事件就可以工作并调用指定的方法。但如果我把5-8,什么都不管用。为什么?
用于combobox
的XAML,在windows phone 8.1 Win RT 中发生选择更改事件
<ComboBox HorizontalAlignment="Center" Margin="19,9.5,19,9.5" SelectionChanged="ComboBox_SelectionChanged" Header="Choose the type of the plot" FontSize="15">
<ComboBoxItem Content="Signal Winner" IsSelected="True" Tag="SW"/>
<ComboBoxItem Content="Filtered signal Winner" Tag="FSW"/>
<ComboBoxItem Content="Quality Winner" Tag="QW"/>
<ComboBoxItem Content="Error Winner" Tag="EW"/>
<ComboBoxItem Content="Signal LMS" Tag="SL"/>
<ComboBoxItem Content="Filtered signal LMS" Tag="FSL" />
<ComboBoxItem Content="Quality LMS" Tag="QL"/>
<ComboBoxItem Content="Error LMS" Tag="EL"/>
</ComboBox>
如何从组合框中获取所选项目。
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox cb = sender as ComboBox;
ComboBoxItem selectedItem = cb.SelectedItem as ComboBoxItem;
switch (selectedItem.Tag.ToString())
{
case "SW":
//first item selected...
break;
case "FSW":
// Second item selected..
break;
case "QW":
break;
}
}
还可以查看这个关于如何使用组合框的示例。http://www.c-sharpcorner.com/UploadFile/2d2d83/combobox-in-windows-phone-8-1/