У меня есть 2 свойства зависимости:
public static readonly DependencyProperty GroupsProperty = DependencyProperty.Register(
nameof(Groups), typeof(IEnumerable<string>), typeof(MyControl), new PropertyMetadata(null, GroupsChangedCallback));
public IEnumerable<string> Groups
{
get => (IEnumerable<string>) GetValue(GroupsProperty);
set => SetValue(GroupsProperty, value);
}
public static readonly DependencyProperty VisibleGroupsProperty = DependencyProperty.Register(
nameof(VisibleGroups), typeof(IEnumerable<string>), typeof(MyControl), new PropertyMetadata(null));
public IEnumerable<string> VisibleGroups
{
get => (IEnumerable<string>)GetValue(GroupsProperty);
set => SetValue(GroupsProperty, value);
}
Я связываю ItemsControl с группами, и в DataTemplate мне бы хотелось установить Visibility на Collapsed, если в VisibleGroups текущей группы нет.
<ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MyControl}}, Path=Groups}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- here -->
<Grid Visibility="{Visible if VisibleGroups contains current group}">
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Есть ли простой способ сделать это, или я должен создать отдельную «Групповую» модель представления, такую как:
public class Group
{
public string Name {get;set;}
public bool IsVisible {get;set;}
}