简体   繁体   English

WPF:将TextBlock文本值绑定到WPF中的所选按钮内容:纯XAML

[英]WPF: Bind TextBlock Text Value to Selected Button Content in WPF: Pure XAML

Not sure if this can be done - I've got a WPF Application with a bunch of XAML screens and what I'd like to be able to do on one of them is bind the Text value of a TextBlock to the Content Value of a selected button. 不知道是否可以这样做-我有一个带有一堆XAML屏幕的WPF应用程序,而我想在其中一个屏幕上执行的操作是将TextBlock的Text值绑定到一个选择的按钮。 I've got say 5 buttons in my XAML and when I click any of them I want the text block to reflect the button content. 我在XAML中说了5个按钮,当我单击其中的任何一个时,我都希望文本块反映按钮的内容。 I know I can do this through Commands ala MVVM but I'd love to do this in pure XAML - no code at all. 我知道我可以通过Commands ala MVVM来做到这一点,但是我很想在纯XAML中做到这一点-完全没有代码。

Can it be done? 能做到吗

Thanks heaps! 谢谢堆!

Answers below! 下面的答案!

Chris W response: Chris W回应:

Add a trigger on your buttons individually or as a template shared by all of them to do a ChangePropertyAction with your TextBlock as the TargetObject to its Text property with the Buttons content and voila, you're done. 在按钮上单独添加触发器或将其添加为所有按钮共享的模板,以将TextBlock作为TargetObject进行ChangePropertyAction,并将其添加到Buttons内容的Text属性中,这样就完成了。

XAMIMAX response: XAMIMAX响应:

Set the Trigger for your button, in the 在按钮中设置触发按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM