0

下面是一幅精美的作品,它代表了一个 WPF 表单,左侧是列表框,右侧是内容控件。我想设置它,所以如果列表框为空,那么内容控件是不可见的。我应该挂钩什么属性/事件?

----- -----
| a | | c |
| b | |   |
----- -----
4

1 回答 1

3

您应该为 ContentControl 创建一个样式,并使用触发器来确定列表何时有 0 个项目,如下所示:

<ListBox x:Name="uiList">...</ListBox>
<ContentControl>
        <ContentControl.Content>
            <TextBox Text="List has items." />
        </ContentControl.Content>
        <ContentControl.Style>
            <Style TargetType="{x:Type ContentControl}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=uiList, Path=Items.Count}"
                                 Value="0">
                        <Setter Property="Visibility"
                                Value="Collapsed" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ContentControl.Style>
    </ContentControl>
于 2009-06-26T20:05:51.250 回答