Reputation: 16726
I would like to create (extend core button class probably) basic button programmatically on request and add it to a main canvas when ready. Is it possible to set a styling from the code (it is going to be width/height and transparent background, nothing else), rather then having visual styles in xaml file?
Upvotes: 1
Views: 82
Reputation: 50672
A Style is just another class.
Style buttonStyle = new Style(typeof(Button));
buttonStyle.Setters.Add(new Setter(Button.WidthProperty, 100));
buttonStyle.Setters.Add(new Setter(Button.HeightProperty, 75));
buttonStyle.Setters.Add(new Setter(Button.BackgroundProperty, new SolidBrush(...)));
myButton.Style = buttonStyle;
Upvotes: 4