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 上使用触发器?
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
