Is it possible to use Triggers on Grid RowDefinitions?(是否可以在 Grid RowDefinitions 上使用触发器?)
问题描述
我有一个网格,它的行需要根据视图模型动态调整大小.我想做类似以下的事情:
I have a grid whose rows need to be resized dynamically based on the view model. I'd like to do something like the following:
<RowDefinition Height="2*">
<RowDefinition.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=ShowSection}" Value="True">
<Setter Property="RowDefinition.Height" Value="2*"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=ShowSection}" Value="False">
<Setter Property="RowDefinition.Height" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
这编译,没有抛出错误,但似乎没有任何效果.是我遗漏了什么,还是 Grid 不允许在绘制表单后调整其行的大小或类似的东西?
This compiles, throws no errors, but doesn't seem to have any effect. Is there something I'm missing, or does the Grid not allow its rows to resize after the form is drawn or something to that effect?
推荐答案
我认为您的 Xaml 代码的唯一问题是您通过在 RowDefinition
上显式设置 Height 来覆盖 DataTrigger.尝试使用 Setter 代替
I think the only problem with your Xaml code is that you're overwriting the DataTrigger by setting Height explictly on the RowDefinition
. Try with using a Setter instead
<RowDefinition>
<RowDefinition.Style>
<Style>
<Setter Property="RowDefinition.Height" Value="2*"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=ShowSection}" Value="True">
<Setter Property="RowDefinition.Height" Value="2*"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=ShowSection}" Value="False">
<Setter Property="RowDefinition.Height" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
这篇关于是否可以在 Grid RowDefinitions 上使用触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以在 Grid RowDefinitions 上使用触发器?
基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01