wpf - Change Button.Content through style programmatically -


I want to change the contents of the button programmatically via style change. I've created a style, which has been added a setter for the button. ContentProfile , set a new style on the button, but the content did not change.

I know that I can set the button content directly, but now I want to know why this does not work:

  style aStyle = new style (); Setter buster = new setter (); BSetter.Property = Button.ContentProperty; BSetter.Value = "some text"; AStyle.Setters.Add (bSetter); AButton.Style = aStyle;  

XML:

  & lt; Button x: name = "aButton" style = "{x: tap}" click = "button_link" />  

I can change the look of a button like this, but I Could not change. BTW, I got an example on WPF in MCTS Book.

Any ideas?

This code works for me as well as you definitely do content from another location Not changing? You can try

  var source = DependencyPropertyHelper.GetValueSource (aButton, ContentControl.ContentProperty);  

... to understand it. I like to use WPF snoop for this.


Comments