按钮单击在 WPF 中使用触发器更改 DataGrid 的可见性

编程入门 行业动态 更新时间:2024-10-27 12:32:15
本文介绍了按钮单击在 WPF 中使用触发器更改 DataGrid 的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试找到某种方法,当单击按钮时更改其他控件的可见性,例如在 XAML 中带有触发器的 DataGrid.

Hi i am trying to find some way to when a button is clicked changes the visibility of other control, like a DataGrid with a Trigger in XAML.

该按钮仅将 DataGrid 的可见性更改为 Visible,它在代码隐藏中执行其他操作,但我认为这可以在带有触发器的样式中完成.

The button only changes the visibility of the DataGrid to Visible, it does other things in Code Behind, but this is something that i think that can be done in a Style with a Trigger.

我试图找到一个解决方案,似乎可以做到,但我不明白怎么做.

I tried to find a solution and it seems to be possible to do but i can't understand how.

提前致谢.

推荐答案

<Button Content="Button!"> <Button.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.Target="{x:Reference dataGrid}" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button>

{x:Reference dataGrid} 引用名为 dataGrid 的 DataGrid,或者您可以使用 Storyboard.TargetName.如果要绑定或引用资源,通常会使用 Storyboard.Target 属性.

{x:Reference dataGrid} references a DataGrid with the name dataGrid, alternatively you could just use Storyboard.TargetName. You would normally use the Storyboard.Target property if you do binding or references to resources.

更多推荐

按钮单击在 WPF 中使用触发器更改 DataGrid 的可见性

本文发布于:2023-11-12 04:57:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580569.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   单击   按钮   见性   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!