我是C#的新手,我正在尝试使用Surface 2.0 SDK和C#开发Microsoft PixelSense应用程序。
我正在使用以下字符串将我的项目加载到下拉菜单中:
_Menu1.ItemsSource = new string[] {
"All",
"Housing",
"Transportation",
"Food",
"Personal Insurance",
"Health",
"Entertainment",
"Personal care",
"Cash",
"Misc",
};
现在我想调用if语句,例如选择“Housing”。然后if语句应该启用一个按钮。
我尝试了以下内容:
if (_Menu1.ItemSource == 1){
_Menu3.IsEnabled = true;
};
这显然不起作用,但它说明了我正在努力实现的目标。
答案 0 :(得分:2)
那不是:
_Menu1.SelectedIndex == 1
答案 1 :(得分:0)
我个人不喜欢硬编码的索引值。所以:
var dataString = new string[]
{
"All",
"Housing",
"Transportation",
"Food",
"Personal Insurance",
"Health",
"Entertainment",
"Personal care",
"Cash",
"Misc",
};
_Menu1.ItemsSource = dataString;
var index = dataString.ToList().IndexOf("Housing");
_Menu1.SelectedIndex == index;