views:

287

answers:

1

Hello all, i have customized ListBox declared in XAML:

<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>

I need to dsiplay and interop with generic List, where T is:

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 is pretty simple Base class:

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

When i turn Activated property programmatically, checkbox do not change state. Debug: PropertyChanged = null. Anybody know, what is incorrect?

+1  A: 

One obvious problem meets the eye: TemplatedParent is for use with ControlTemplates. Since you're using a DataTemplate, this should work:

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

I didn't notice any problems with the C#.

Ray Burns
Thank you, Ray! I have removed explicit RelativeSource and now its work!
Pavel