2016-05-30 2 views
0

こんにちは私はコンボボックスに16個のボタンをバインドしていますが、ウィンドウがロードされてからコンボボックスから新しい色を選択すると、ボタンの背景が変わらないので問題はありません。ボタンが正しく動作しないComboBox(ソース)をバインドします。

これは私が(Shape1Colorがコンボボックスと言われている)は、結合しています方法です:

for (int i = 0; i < Shape1.Children.Count; i++) 
     { 
      Binding btnbinding = new Binding(); 
      btnbinding.Converter = new ButtonColorConverter(); 
      btnbinding.Source = Shape1Color.SelectedItem; 
      btnbinding.NotifyOnSourceUpdated = true; 
      (Shape1.Children[i] as Button).SetBinding(Button.BackgroundProperty, btnbinding); 

     } 

たときに、ウィンドウがロードだから、それだけで動作しますが、私はコンボボックスから新しい項目を選択したとき、それは私のコンバータを入力し、私はありませんなぜか分からない。

+0

なぜバインディングにはSelectedItemがSourceとしてあり、Pathとしてではありませんか?私はおそらく、Shape1ColorとSelectedItemへのパスへのソースを持っているだろう – nkoniishvt

答えて

0
Sourceを結合として

トライ使用Shape1Colorbtnbinding.Source = Shape1Color.SelectedItem;作品が、一度だけの設定

Binding btnbinding = new Binding(); 
btnbinding.Converter = new ButtonColorConverter(); 
btnbinding.Source = Shape1Color; 
btnbinding.Path = new PropertyPath("SelectedItem"); 
btnbinding.NotifyOnSourceUpdated = true; 

を結合するためのPathとしてSelectedItemを設定します。 SelectedItemが変更されたときに変更されません

+0

ありがとう – user3112193

関連する問題