【发布时间】:2015-10-01 11:34:25
【问题描述】:
我有一个 WPF 数据网格,它有一个集合视图源,上面有 3 个级别的分组。
我已将数据网格设置为使用 3 个扩展器,使其看起来像这样:
Level 1 Expander
<content>
Level 2 Expander
<content>
Level 3 Expander
<content>
Level 2 和 Level 1 只是组的标题
我有第二个控件,它允许用户显示和隐藏 3 级项目,它通过将 3 级扩展器绑定到后面对象中的布尔“IsVisible”属性来工作。
<!-- Style for groups under the top level. this is the style for how a sample is displayed -->
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<!-- The parent control that determines whether or not an item needs to be displayed. This holds all of the sub controls displayed for a sample -->
<Expander Margin="2"
Background="{Binding Path=Name,
Converter={StaticResource SampleTypeToColourConverter}}"
IsExpanded="True"
Visibility="{Binding Path=Items[0].IsVisibleInMainScreen,
Converter={StaticResource BoolToVisibilityConverter}}">
这种方法效果非常好。
但是
如果用户取消选择 3 级扩展器中的所有项目,则 2 级扩展器标题仍会显示,这意味着有价值的房地产已用完,显示没有可见数据的组标题。
我想要一种将 2 级扩展器的可见性绑定到其子控件的方法,并说“如果所有子控件都可见,则显示扩展器,否则将其折叠”
这可能吗?
【问题讨论】:
-
如果所有子项都可见,则显示扩展器,否则将其折叠听起来像是一个转换器任务。您已经拥有
IsVisibleInMainWindow属性,当孩子折叠时更改它。注意:Items应该是ObservableCollection。 -
你能给我们一个更完整的xaml,包括所有的扩展器吗?
-
我认为我们确实需要更多的 xaml。