我有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中,如果当前组在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>
有没有简单的方法可以做到这一点,或者我应该创建一个单独的“ Group” ViewModel,例如:
public class Group
{
public string Name {get;set;}
public bool IsVisible {get;set;}
}
答案 0 :(得分:1)
没有“简单的方法”可以做到这一点。您需要编写一些代码来确定在plugin.fire('newAnnotation', {
id: 1,
range: { start: 20, end: null },
shape: { // NOTE - x/y vals are % based (Floats) in video, not pixel values
x1: null,
x2: null,
y1: null,
y2: null
}
commentStr: "This is my comment." // THIS DATA YOU NEED TO FILL
});
中是否有对当前项目的引用。
例如,您可以创建一个VisibleGroups
来检查IMultiValueConverter
是否包含values[1]
:
values[0]