GridSplitter 覆盖 ColumnDefinition 的样式触发器? [英] GridSplitter overrides ColumnDefinition's style trigger?

查看:18
本文介绍了GridSplitter 覆盖 ColumnDefinition 的样式触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题...
看起来使用 GridSplitter 调整 Grid 列的大小会禁用(或以其他方式停用)在 Grid 列上定义的触发器.

I ran into a strange issue...
It looks like resizing Grid's columns using a GridSplitter disables (or otherwise deactivates) the trigger defined on a Grid's column.

这是我的设置:

一个 Grid 有 3 列,定义如下:

A Grid has 3 columns, defined as follows:

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition>
        <ColumnDefinition.Style>
            <Style>
                <Setter Property="ColumnDefinition.Width" Value="Auto"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=OpenItemViewModels.Count}" Value="0">
                        <Setter Property="ColumnDefinition.Width" Value="0"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ColumnDefinition.Style>
    </ColumnDefinition>
    <ColumnDefinition>
        <ColumnDefinition.Style>
            <Style>
                <Setter Property="ColumnDefinition.Width" Value="4*"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=OpenItemViewModels.Count}" Value="0">
                        <Setter Property="ColumnDefinition.Width" Value="0"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ColumnDefinition.Style>
    </ColumnDefinition>
</Grid.ColumnDefinitions>

期望的是,当第三列中没有构成控件的ItemsSource的项时,将0宽度分配给第二列和第三列(承载GridSplitter和辅助项控件, 分别).

The expectation is that when there are no items that constitute ItemsSource for the control in the third column, 0 width will be assigned to the second and third columns (hosting the GridSplitter and the auxiliary items control, respectively).

只要我不触摸拆分器(当辅助控件中的所有选项卡都关闭时,只有第一列仍然可见),它就可以正常工作.
如果我移动拆分器,问题就开始了,从而有效地改变了 ##0 和 2 列之间的比例.在这种情况下,当右侧控件中的所有项目都关闭时,这些列的宽度不会重置.

This works well as long as I don't touch the Splitter (when all the tabs in the auxiliary control are closed, only the first column remains visible).
The problems start if I move the splitter, thus effectively changing the proportion between columns ##0 and 2. In such scenario, these columns' width is not reset when all the items in the right-hand control are closed.

我怀疑这与 GridSplitter 否决"我在 XAML 中的定义有关.

I suspect this has something to do with the GridSplitter "overruling" my definitions in XAML.

有人可以确认/反驳这个理论,并建议如何解决这个问题吗?

Can someone please confirm / disprove this theory, and suggest how to work around the problem?

推荐答案

我遇到了同样的行定义问题.Gridsplitter 将覆盖我们在样式或设置器中提供的任何内容.可以使用动画来解决(因为动画在依赖属性值解析中具有最高优先级).对第三列执行相同操作.

I had the same problem for rowdefinition. Gridsplitter will override whatever we give in style or setters. It can be solved using animation (since animation has the highest priority in dependency property value resolution). Do the same for the third column.

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition>
    <ColumnDefinition.Style>
        <Style>
            <Setter Property="ColumnDefinition.Width" Value="Auto" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=OpenItemViewModels.Count}" Value="0">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Name="BeginStoryboard1">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Width">
                                    <ObjectAnimationUsingKeyFrames.KeyFrames>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                Value="{x:Static GridLength.Auto}" />
                                    </ObjectAnimationUsingKeyFrames.KeyFrames>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <RemoveStoryboard BeginStoryboardName="BeginStoryboard1" />
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ColumnDefinition.Style>
</ColumnDefinition>

这篇关于GridSplitter 覆盖 ColumnDefinition 的样式触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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