I would like to programmatically change content of button via style change. I created a style, added setter for Button.ContentProperty
, set new style to button, but content was not changed.
I know that I can set button content directly, but now I would like to know why this does not work:
Style aStyle = new Style();
Setter bSetter = new Setter();
bSetter.Property = Button.ContentProperty;
bSetter.Value = "Some Text";
aStyle.Setters.Add(bSetter);
aButton.Style = aStyle;
XAML:
<Button x:Name="aButton" Style="{x:Null}" Click="Button_Click" />
I could change appearance of a button this way, but I couldn't change content. Btw, I found example in MCTS book on WPF.
Any idea?