質問

I'm new to C# and I am trying to develop an application for a Microsoft PixelSense using Surface 2.0 SDK and C#.

I'm loading my items into my dropdown menu using a string as followed:

_Menu1.ItemsSource = new string[] {
    "All",
    "Housing",
    "Transportation",
    "Food",
    "Personal Insurance",
    "Health",
    "Entertainment",
    "Personal care",
    "Cash",
    "Misc",
};

Now I want to call an if statement if for example "Housing" is selected. The if statement should then enable a button.

I tried the following:

if (_Menu1.ItemSource == 1){
    _Menu3.IsEnabled = true;   
};

This is obviously not working but it illustrates what I'm trying to accomplish.

役に立ちましたか?

解決

Wouldn't that be:

_Menu1.SelectedIndex == 1

他のヒント

I personally don't like index values hardcoded. So:

        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;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top