я хочу чтобы работали кнопки CheckEdit
делаю биндинг через проперти MyProperty данные виводяться хорошо, но мне еще нужно чтобы IsChecked="{Binding Path=IsChecked}"
работал. Я сделал проперти, но почему то не работает, как исправить ?
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}}
?ItemsControl
, но дляItemsControl.ItemTemplate
DateContext устанавливается в элементы списка, который установлен вItemsSource
, т.е. для вашего случая этоMyProperty
. Чтобы починить binding, Вам надо поиграться сRelativeSource
иAncestor
.