2012-02-24 16 views
0

ListBox ItemでisEnabledプロパティをfalseに設定しようとしています。コードにはデザイナーでどのように行われているかを示すいくつかのxamlが含まれていますが、コードでそれを行う必要があります。ListBox Items isEnabled WP7

string[] names = { "alpha", "beta", "gamma", "delta" }; 

     for (int i = 0; i < names.Length; i++) 
     { 
      listBox1.Items.Add(names[i].ToString()); 

      //set items 2 & 4 to isEnabled=false 
      // <ListBoxItem Content="beta" IsEnabled="False" /> xaml code 

      // My Attempt, does not compile, cannot be used like a method 
      // listBox1.isEnabled(2,false); 


     } 

これは、C#/ Silverlightを使用してWindowsPhone7アプリです:

は、ここに私のコードです。

答えて

-1

方法について:

listBox1.Items.Add(new ListBoxItem() { Content = "one", IsEnabled = true }); 
listBox1.Items.Add(new ListBoxItem() { Content = "two", IsEnabled = false}); 

次に、あなたが例えば3番目の項目のためにそれを設定したい場合は、

void listbox1_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     ListBoxItem selectedItem = listbox1.SelectedItem; 
     stirng content = selectedItem.Content.ToString() 
    } 
+0

gabnfill、それはListBoxにアイテムを追加しますが、リンクを押すと、Selection_Changedイベントは文字列を "e"引数として持ちません。 e.AddedItemes [0] .ToString()の値は "alpha"でした。何か案は? –

+0

@TreyBalut選択した項目を取得し、ListBoxItemにキャストします。コンテンツを取得し、文字列にキャスト –

-1

を行うことができ、選択した項目を取得したいとき:

listBox1.Items[2].IsEnabled = false; 
+0

オブジェクトを取得すると、「IsEnabled」プロパティの定義がありません。 –

関連する問題