I want the CheckEdit buttons to work; I do the binding through the proprietary MyProperty data to be injected well, but I still need IsChecked="{Binding Path=IsChecked}" work. I did it, but for some reason it doesn't work, how can I fix it?

XAML

  <ItemsControl ItemsSource="{Binding MyProperty}" Margin="0" Grid.Column="1" Grid.RowSpan="1" > <ItemsControl.ItemTemplate> <DataTemplate> <dxe:CheckEdit Content="{Binding}" Padding="2.5" Margin="3" IsChecked="{Binding Path=IsChecked}"/> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Orientation="Vertical" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> 

C #

 List<string> arrayList = new List<string>(); foreach (DataText item in DataT) { bool exists = false; foreach (var it in types) { if (it == item.TypeFiles) { arrayList.Add(item.TypeFiles); Items.Add(new MyCheckBox(item.TypeFiles, IsChecked)); } } } uniqueList = new List<string>(arrayList.Distinct()); MyProperty = uniqueList; } private bool? _isChecked = null; public bool? IsChecked { get { return _isChecked; } set { _isChecked = value; OnPropertyChange("IsChecked"); } } public List<string> MyProperty { get { return uniqueList; } set { uniqueList = value; OnPropertyChange("MyProperty"); } } 
  • and what if such a binding: IsChecked="{Binding DataContext.IsChecked, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}} ? - ixSci
  • no so does not work either - momo
  • Well, binding in your code will definitely not work, because You use the property from the DataContext, which is set for ItemsControl , but for ItemsControl.ItemTemplate DateContext is set to the items in the list that is set in the ItemsSource , i.e. for your case, this is MyProperty . To fix the binding, you need to play around with RelativeSource and Ancestor . - ixSci

2 answers 2

By default, the unidirectional binding mode, you can set Mode = TwoWay manually https://msdn.microsoft.com/ru-ru/library/system.windows.data.binding.mode(v=vs.110).aspx

  • I have already tried to do this, all without any changes - momo

I made a class in which I placed the name and isChecked , and dynamically unloaded it from the array:

  public bool? IsChecked { get; set; } public string FilePath { get; set; } public MyCheckBox(string FilePath, bool? IsChecked) { this.FilePath = FilePath; this.IsChecked = IsChecked; } TempList = new List<MyCheckBox>(); foreach (var type in tempUniqueList) { TempList.Add(new MyCheckBox(type, true)); } MyProperty = TempList; 

XAML

 <DataTemplate> <dxe:CheckEdit Content="{Binding FilePath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Padding="2.5" Margin="3" IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> </DataTemplate>