0

XAML で宣言された ListBox をカスタマイズしました。

<ListBox x:Name="uicMDSQonfServer">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal"
                  Margin="0,5,0,5">
        <CheckBox IsChecked="{Binding RelativeSource={TemplatedParent},
                                      Path=Activated}" />
        <ContentPresenter Content="{Binding RelativeSource={TemplatedParent},
                                    Path=Content}"/>
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

T が次のような一般的な List を表示して相互運用する必要があります。

public class QonfServer: QonfBase, INotifyPropertyChanged
{
        private string ip;
        private bool activated;

        public string Ip {
            get { return ip; }
        }

        public bool Activated
        {
            get { return activated; }
            set
            {
                if (activated == value)
                    return;

                activated = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Activated"));
            }
        }

        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion
    }

QonfBase は非常に単純な基本クラスです。

public class QonfBase
{
        private int id;
        public  int ID { get; set; }
}

プログラムで Activated プロパティを有効にすると、チェックボックスの状態が変わりません。デバッグ: PropertyChanged = null。誰が知っていますか、何が間違っていますか?

4

1 に答える 1

1

明らかな問題が 1 つ TemplatedParentありますControlTemplate。を使用しているためDataTemplate、これは機能するはずです。

<CheckBox IsChecked="{Binding Activated}" /> 
<ContentPresenter Content="{Binding Content}"/> 

C# に問題はありませんでした。

于 2010-01-21T08:23:02.747 に答える