如果项目隐藏在上下文菜单中,则隐藏分隔符

时间:2013-10-11 08:51:05

标签: xaml visibility separator

我想隐藏所有菜单项时在我的上下文菜单中隐藏分隔符。 如果两个菜单项中至少有一个可见,则分隔符也必须可见。

我试过了:

<Separator>
    <Separator.Style>
        <Style TargetType="Separator">
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=Visibility, ElementName=Item1}" Value="Collapsed" />
                        <Condition Binding="{Binding Path=Visibility, ElementName=Item2}" Value="Collapsed" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Separator.Visibility" Value="Collapsed" />
                </MultiDataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=Visibility, ElementName=Item1}" Value="Visible" />
                        <Condition Binding="{Binding Path=Visibility, ElementName=Item2}" Value="Visible" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Separator.Visibility" Value="Visible" />
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
    </Separator.Style>
</Separator>

<MenuItem x:Name="Item1"  Header="Item1" Visibility="{Binding Item1Visibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<MenuItem x:Name="Item2"  Header="Item2" Visibility="{Binding Item2Visibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>

但是分隔符始终是隐藏的。 我的代码出了什么问题?

0 个答案:

没有答案