是否可以在网格行定义上使用触发器?
我有一个网格,其行需要根据视图模型动态调整大小。我想做类似以下的事情:
<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>
这可以编译,不会引发任何错误,但似乎没有任何效果。是否有我遗漏的东西,或者网格是否不允许在绘制表单后调整其行大小或达到此效果?
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>
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的 Xaml 代码的唯一问题是您通过在
RowDefinition
上显式设置高度来覆盖 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我知道这篇文章已经有 3 年历史了,但它仍然可能对某人有所帮助。
我处于同样的情况,我设法通过将 TargetType 设置为 RowDefinition 来使其工作。
I know this post is 3 years old, but still it might help someone.
I was in same situation, i managed to get it working by setting TargetType to RowDefinition.