【问题标题】:Windows Phone 8.1 ComboBox Tapped event don't workWindows Phone 8.1 ComboBox Tapped 事件不起作用
【发布时间】:2015-12-22 21:08:09
【问题描述】:

您能解释一下为什么我的 ComboBox 中的 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 个项目,点击事件会起作用并调用指定的方法。但是,如果我放 5-8,则没有任何效果。为什么?

【问题讨论】:

  • 你为什么不使用组合框的选择更改事件?
  • @Muhammad Saifullah,组合框没有阳光事件。唯一的事件“Tapped”

标签: c# windows-phone-8.1


【解决方案1】:

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/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多