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"); } }
IsChecked="{Binding DataContext.IsChecked, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}? - ixSciItemsControl, but forItemsControl.ItemTemplateDateContext is set to the items in the list that is set in theItemsSource, i.e. for your case, this isMyProperty. To fix the binding, you need to play around withRelativeSourceandAncestor. - ixSci