MultiDataTrigger使堆栈面板子项可见并显示为colappsed

时间:2017-01-22 11:41:59

标签: c# wpf setter stackpanel multidatatrigger

我有几个属性,如果这些值是真的,

如果为true,我希望堆栈面板子项可见。 如果错误就崩溃了。

据我所知,我需要使用MultiDataTriigers和条件。

然而,我不知道在哪里把二传手提供给Collapsed。

ataching ma XAML代码:

<Style x:Key="ShowHideStyle" TargetType="StackPanel" >
        <Style.Triggers>
            <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                    <Condition Value="True">
                        <Condition.Binding>
                            <MultiBinding Converter="{StaticResource V_converter }">
                                <Binding Path="Type"></Binding>
                                <Binding Path="NodeID"></Binding>
                                <Binding Path="TLV"></Binding>
                            </MultiBinding>
                        </Condition.Binding>
                    </Condition>
                </MultiDataTrigger.Conditions>

                <MultiDataTrigger.Setters>
                    <Setter Property="Visibility" Value="Visible" />
                </MultiDataTrigger.Setters>                    
               </MultiDataTrigger>
        </Style.Triggers>
    </Style>

2 个答案:

答案 0 :(得分:1)

您可以使用MultiBinding绑定到多个属性,并且仅当实现IMultiValueConverter接口的转换器类返回true时,才将StackPanel的Visibility属性设置为Visible:

<Style x:Key="ShowHideStyle" TargetType="StackPanel">
    <!-- default Visibility: -->
    <Setter Property="Visibility" Value="Collapsed" />
    <Style.Triggers>
        <DataTrigger Value="True">
            <DataTrigger.Binding>
                <MultiBinding Converter="{StaticResource V_converter}">
                    <Binding Path="Type" />
                    <Binding Path="NodeID" />
                    <Binding Path="TLV" />
                </MultiBinding>
            </DataTrigger.Binding>
            <Setter Property="Visibility" Value="Visible" />
        </DataTrigger>
    </Style.Triggers>
</Style>

答案 1 :(得分:0)

会不会像以下那样工作 - 默认崩溃了? 我的WPF有点生疏,但如下所示:

<Style x:Key="ShowHideStyle" TargetType="StackPanel" >
    <Style.Setters>
        <Setter Property="Visibility" Value="Collapsed" />
    </Style.Setters>
    <Style.Triggers>
        <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
                <Condition Value="True">
                    <Condition.Binding>
                        <MultiBinding Converter="{StaticResource V_converter }">
                            <Binding Path="Type"></Binding>
                            <Binding Path="NodeID"></Binding>
                            <Binding Path="TLV"></Binding>
                        </MultiBinding>
                    </Condition.Binding>
                </Condition>
            </MultiDataTrigger.Conditions>

            <MultiDataTrigger.Setters>
                <Setter Property="Visibility" Value="Visible" />
            </MultiDataTrigger.Setters>                    
           </MultiDataTrigger>
    </Style.Triggers>
</Style>

注意第二行和Visibility setter下面的一行。