C# UWP how to get the value of changed ComboBoxItem

前端 未结 3 1457
独厮守ぢ
独厮守ぢ 2021-01-23 08:11

In my .xaml file I have my combo box as below:

相关标签:
3条回答
  • 2021-01-23 08:38

    You can do it like following

    private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                var comboBoxItem = e.AddedItems[0] as ComboBoxItem;
                if (comboBoxItem == null) return;
                var content = comboBoxItem.Content as string;
                if (content != null && content.Equals("some text"))
                {
                    //do what ever you want
                }
            }
    
    0 讨论(0)
  • 2021-01-23 08:47

    You can use the SelectedItem property of the combobox

    (CLengthCombo.SelectedItem as ComboBoxItem).Content
    

    https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.combobox.aspx#properties

    0 讨论(0)
  • 2021-01-23 08:49

    Get your combobox to work this, c.(...) has SelectedItem, SelectedText ...:

    private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var c = sender as ComboBox;
    
        var item = c.(...);
    }
    
    0 讨论(0)
提交回复
热议问题