您可以在组框的知名度绑定到它的孩子们的知名度? [英] Can you bind the visibility of a GroupBox to the visibility of it's children?

查看:129
本文介绍了您可以在组框的知名度绑定到它的孩子们的知名度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,试图获得一个分组框崩溃。我想一个分组框,如果所有它的孩子们晕倒,这将崩溃。



我已成功,为达到这一使用multibinding的属性,如下所示。



<预类=郎咸平的XML prettyprint-覆盖> <&StackPanel的GT;
<分组框中>
< GroupBox.Visibility>
< MultiBinding
转换器={StaticResource的multiBoolOrToVis}
ConverterParameter ={X:静态Visibility.Collapsed}
>
<绑定路径=a_visible/>
<绑定路径=b_visible/>
< / MultiBinding>
< /GroupBox.Visibility>
< GroupBox.Header>
<标签内容=分组框/>
< /GroupBox.Header>
<&StackPanel的GT;
<标签
含量=A
能见度={绑定路径= a_visible,转换器= {StaticResource的boolToVis}}
/>
<标签
含量=B
能见度={绑定路径= b_visible,转换器= {StaticResource的boolToVis}}
/>
< / StackPanel的>
< /分组框中>
<网格和GT;
< Grid.ColumnDefinitions>
< ColumnDefinition WIDTH =*/>
< ColumnDefinition WIDTH =*/>
< /Grid.ColumnDefinitions>
<复选框
含量=可见的
Grid.Column =0
Grid.Row =1
=器isChecked{绑定路径= a_visible,模式=双向}
/>
将;复选框
含量=B可见
Grid.Column =1
Grid.Row =1
器isChecked ={结合路径= b_visible,模式=双向}
/>
< /网格和GT;
< / StackPanel的>



这个问题是我们希望能够以这种多次做,不用担心留下关闭绑定。所以我的问题是有这样做的一般,最好是在一种风格的任何方式。另一个要求是它必须是在XAML并不落后代码。



所以我理想的答案是一种风格,所以我可以在我的XAML以下。



<预类=郎咸平的XML prettyprint-覆盖> <&StackPanel的GT;
<分组框样式=ChildrenVisibilityStyle>
< GroupBox.Header>
<标签内容=分组框/>
< /GroupBox.Header>
<&StackPanel的GT;
<标签
含量=A
能见度={绑定路径= a_visible,转换器= {StaticResource的boolToVis}}
/>
<标签
含量=B
能见度={绑定路径= b_visible,转换器= {StaticResource的boolToVis}}
/>
< / StackPanel的>
< /分组框中>
<网格和GT;
< Grid.ColumnDefinitions>
< ColumnDefinition WIDTH =*/>
< ColumnDefinition WIDTH =*/>
< /Grid.ColumnDefinitions>
<复选框
含量=可见的
Grid.Column =0
Grid.Row =1
=器isChecked{绑定路径= a_visible,模式=双向}
/>
将;复选框
含量=B可见
Grid.Column =1
Grid.Row =1
器isChecked ={结合路径= b_visible,模式=双向}
/>
< /网格和GT;
< / StackPanel的>



我已经看过这些问题,他们使我认为这是不可能的; 在ControlTemplate中结合,的 StackPanel的知名度,的边境知名度



很抱歉,如果这已经回答过了。感谢您预先的任何答案/评论。


解决方案

您可以使用 MultiDataTrigger 折叠分组框当儿童被倒塌



下面是一个工作的例子:

 <&StackPanel的GT; 
<分组框中>
< GroupBox.Header>
<标签内容=分组框/>
< /GroupBox.Header>
<&StackPanel的GT;
<标号x:名称=lbl_aCONTENT =A能见度={结合器isChecked,的ElementName = chk_a,转换器= {StaticResource的boolToVis}}/>
<标号x:名称=lbl_bCONTENT =B能见度={结合器isChecked,的ElementName = chk_b,转换器= {StaticResource的boolToVis}}/>
< / StackPanel的>
< GroupBox.Style>
<风格的TargetType =分组框>
< Style.Triggers>
< MultiDataTrigger>
< MultiDataTrigger.Conditions>
<条件绑定={结合能见度,的ElementName = lbl_a}VALUE =折叠/>
<条件绑定={结合能见度,的ElementName = lbl_b}VALUE =折叠/>
< /MultiDataTrigger.Conditions>
< MultiDataTrigger.Setters>
< setter属性=GroupBox.VisibilityVALUE =折叠/>
< /MultiDataTrigger.Setters>
< / MultiDataTrigger>
< /Style.Triggers>
< /样式和GT;
< /GroupBox.Style>
< /分组框中>

<复选框X:NAME =chk_aCONTENT =可见Grid.Column =0Grid.Row =1/>
<复选框X:NAME =chk_bCONTENT =B可见Grid.Column =1Grid.Row =1/>

< / StackPanel的>


I have an issue trying to get a GroupBox to collapse. I want a GroupBox which will collapse if all it's children are collapsed.

I have managed to achieve this using a multibinding to the properties, as shown below.

<StackPanel>
    <GroupBox>
      <GroupBox.Visibility>
        <MultiBinding 
          Converter="{StaticResource multiBoolOrToVis}"
          ConverterParameter="{x:Static Visibility.Collapsed}"
        >
          <Binding Path="a_visible"/>
          <Binding Path="b_visible"/>
        </MultiBinding>
      </GroupBox.Visibility>
        <GroupBox.Header>
        <Label Content="GroupBox"/>
      </GroupBox.Header>
      <StackPanel>
        <Label 
          Content="A"
          Visibility="{Binding Path=a_visible, Converter={StaticResource boolToVis}}"
        />
        <Label 
          Content="B"
          Visibility="{Binding Path=b_visible, Converter={StaticResource boolToVis}}"
        />
      </StackPanel>
    </GroupBox>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <CheckBox 
        Content="A Visible"
        Grid.Column="0"
        Grid.Row="1"
        IsChecked="{Binding Path=a_visible, Mode=TwoWay}"
      />
      <CheckBox 
        Content="B Visible"
        Grid.Column="1"
        Grid.Row="1"
        IsChecked="{Binding Path=b_visible, Mode=TwoWay}"
      />
    </Grid>
  </StackPanel>

The problem with this is we want to be able to do this multiple times and not worry about leaving off a binding. So my question is there any way of doing this generically, preferably in a style. Another requirement is that it has to be in xaml not code behind.

So my ideal answer would be a style so I could the following in my xaml.

<StackPanel>
    <GroupBox Style="ChildrenVisibilityStyle">
        <GroupBox.Header>
        <Label Content="GroupBox"/>
      </GroupBox.Header>
      <StackPanel>
        <Label 
          Content="A"
          Visibility="{Binding Path=a_visible, Converter={StaticResource boolToVis}}"
        />
        <Label 
          Content="B"
          Visibility="{Binding Path=b_visible, Converter={StaticResource boolToVis}}"
        />
      </StackPanel>
    </GroupBox>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <CheckBox 
        Content="A Visible"
        Grid.Column="0"
        Grid.Row="1"
        IsChecked="{Binding Path=a_visible, Mode=TwoWay}"
      />
      <CheckBox 
        Content="B Visible"
        Grid.Column="1"
        Grid.Row="1"
        IsChecked="{Binding Path=b_visible, Mode=TwoWay}"
      />
    </Grid>
  </StackPanel>

I have looked at these questions and they lead me to think that this isn't possible; binding in controltemplate, stackpanel visibility, border visibility.

Sorry if this has been answered before. Thanks in advance for any answers/comments.

解决方案

You could use a MultiDataTrigger to collapse the GroupBox when the Children are collapsed

Here is a working example:

 <StackPanel>
    <GroupBox>
        <GroupBox.Header>
            <Label Content="GroupBox"/>
        </GroupBox.Header>
        <StackPanel>
            <Label x:Name="lbl_a" Content="A" Visibility="{Binding IsChecked, ElementName=chk_a, Converter={StaticResource boolToVis}}"  />
            <Label x:Name="lbl_b" Content="B" Visibility="{Binding IsChecked, ElementName=chk_b, Converter={StaticResource boolToVis}}"  />
        </StackPanel>
        <GroupBox.Style>
            <Style TargetType="GroupBox">
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding Visibility, ElementName=lbl_a}" Value="Collapsed" />
                            <Condition Binding="{Binding Visibility, ElementName=lbl_b}" Value="Collapsed" />
                        </MultiDataTrigger.Conditions>
                        <MultiDataTrigger.Setters>
                            <Setter Property="GroupBox.Visibility" Value="Collapsed" />
                        </MultiDataTrigger.Setters>
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>
        </GroupBox.Style>
    </GroupBox>

    <CheckBox x:Name="chk_a" Content="A Visible" Grid.Column="0" Grid.Row="1" />
    <CheckBox x:Name="chk_b" Content="B Visible" Grid.Column="1" Grid.Row="1"  />

</StackPanel>

这篇关于您可以在组框的知名度绑定到它的孩子们的知名度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆