WPF 中带有 Setter 的 EventTrigger?
我在 WPF 窗口中有一个普通的按钮和文本框,我想要一个带有 EventTrigger 的按钮模板,该事件触发器侦听 Button.Click,然后设置文本框的布尔属性。没有隐藏代码。
像这样的事情:
<ControlTemplate.Triggers>
<EventTrigger SourceName="MyButton" RoutedEvent="Button.Click">
<Setter TargetName="MyTextBox" Property="Focusable" Value="False" />
</EventTrigger>
I have a normal Button and TextBox in a WPF-Window and I want a Template for the Button with a EventTrigger that listens to Button.Click and then sets a boolean-property of the TextBox. No code-behind.
Something like this:
<ControlTemplate.Triggers>
<EventTrigger SourceName="MyButton" RoutedEvent="Button.Click">
<Setter TargetName="MyTextBox" Property="Focusable" Value="False" />
</EventTrigger>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是从 EventTrigger 设置和清除 TextBox 上的
Focusable
的示例。希望您可以根据您的情况调整此示例。
Here is a sample that sets and clears
Focusable
on a TextBox from an EventTrigger.Hopefully you can adapt this example to your situation.
您可以利用行为来实现您想要的结果:
首先,添加引用:
然后,您可以使用交互触发器和 ChangePropertyAction:
您还可以通过指定 TargetObject 来使用它来更改 DataContext 中的属性,如下所示:
You can make use of behaviours to achieve your desired outcome:
First, add the reference:
Afterwards, you can assign a Value to any Property of your choosing using an Interaction Trigger and a ChangePropertyAction:
You can also use this to change properties in your DataContext by specifying a TargetObject like so: