我正在尝试找到某种方法,当单击按钮时更改其他控件的可见性,例如在 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 的可见性
发布评论