C# UWP how to get the value of changed ComboBoxItem

前端 未结 3 1460
独厮守ぢ
独厮守ぢ 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
                }
            }
    

提交回复
热议问题