Ah, I found your problem... I'm sorry, but it's a real basic one too:
private static void Primary_button_onclick(object sender, RoutedEventArgs e)
{
MessageBox.Show("Hello robins");
Button_Primary btn = new Button_Primary();
btn.Background = new SolidColorBrush(Color.fromRgb(0,0,0));
}
Here, you create a new Button_Primary
object and set its Background
property and not the Background
of your UI element:
Button_Primary btn = new Button_Primary();
btn.Background = new SolidColorBrush(Color.fromRgb(0,0,0));
All you need to do is to access your actual Button_Primary
object from the UI... how do you do that? Well, you can find the full story from the How to: Find ControlTemplate-Generated Elements page on MSDN, but the gist of it is this: You need an instance of a control that has the relevant ControlTemplate
applied to it and then you can simply use the FrameworkTemplate.FindName
Method to access the Button
.