簡體   English   中英

將ComboBox(源)與Button綁定不正常。

[英]Binding ComboBox (source) with Buttons not working properly.

您好,我將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);

        }

因此,它僅在窗口加載時有效,但是當我從組合框選擇新項目時,它不會進入轉換器,我也不知道為什么。

嘗試使用Shape1Color作為綁定Source ,並將SelectedItem設置為綁定Path

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

設置btnbinding.Source = Shape1Color.SelectedItem; 有效,但只有一次。 SelectedItem更改時,它不會更改

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM