Reputation: 10251
I want to change content of a Button in XAML using a DataTrigger. Conditionally I need to change the text of the button. However, if the Button initially have a text, the text is not changed. The only way to make it work is either not to set Content
, or set it with a Trigger.
So if I have
<Button Content="Some text" />
the trigger doesn't change the button text.
If I have
<Button />
or
<Button>
<Button.Style>
<Style TargetType="Button">
<Setter Property="Content" Value="Some text" />
</Style>
</Button.Style>
</Button>
the trigger works.
Why?
Upvotes: 0
Views: 951
Reputation: 6501
This is because of DepedencyProperty precedence. see here: http://msdn.microsoft.com/en-us/library/ms743230.aspx
Local values have a higher precedence order than triggers. This means the local value will "take precedence" over the trigger value
When you set it in the Style it changes the precedence. A Trigger takes precedence over a Style Setter and this is why it works as you expect.
Upvotes: 1