How do I bind to another control's property from a trigger?

前端 未结 2 1965
Happy的楠姐
Happy的楠姐 2021-02-02 05:41

In my particular case, I want to bind to the IsReadOnly property of a TextBox to set the Content property of a Button? They are both part of the same StackPanel.

I\'ve t

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 05:57

    You need to specify the trigger as part of a style -- the Triggers collection on the Button itself can only contain event triggers. With that in mind, a DataTrigger works fine. However, there is a wrinkle: the value from the Trigger Setter won't overwrite a local Content property. So you have to set the default Content in the Style as well. Here's how it looks:

    
    

提交回复
热议问题