Need to press some other button before button works in WPF
I'm still fairly new to WPF and only started it under a week ago so I'm not very familiar with very many tags or anything, so sorry if this is something I'm missing thats super obvious. I wanted to learn about resources so I made an app where you can input RGB values into a text box , then those values get converted to a color that the app uses. To actually apply the colors, I have a simple apply button that runs a method that looks like this:
private void ApplyColors(object sender, RoutedEventArgs e)
{
ApplyColorsButton.Focus();
//new brush resources
var AccentBrush = new SolidColorBrush(Color.FromRgb((byte)AccentR, (byte)AccentG, (byte)AccentB));
var PrimaryBrush = new SolidColorBrush(Color.FromRgb((byte)PrimaryR, (byte)PrimaryG, (byte)PrimaryB));
var SecondaryBrush = new SolidColorBrush(Color.FromRgb((byte)SecondaryR, (byte)SecondaryG, (byte)SecondaryB));
//new color resources
Color AccentColor = Color.FromRgb((byte)AccentR, (byte)AccentG, (byte)AccentB);
Color PrimaryColor = Color.FromRgb((byte)PrimaryR, (byte)PrimaryG, (byte)PrimaryB);
Color SecondaryColor = Color.FromRgb((byte)SecondaryR, (byte)SecondaryG, (byte)SecondaryB);
//update brush resources
this.Resources["AccentBrush"] = AccentBrush;
this.Resources["PrimaryBrush"] = PrimaryBrush;
this.Resources["SecondaryBrush"] = SecondaryBrush;
//update color resources
this.Resources["AccentColor"] = AccentColor;
this.Resources["PrimaryColor"] = PrimaryColor;
this.Resources["SecondaryColor"] = SecondaryColor;
}
Here you can see I have 3 different colors: the accent, as well as a primary and secondary color. This works fine and does what its supposed to, but one issue I came across is that the button only works after I press any other button. Say changed the red and blue values for the primary color and click my apply button. It wont do anything until I first click the button that lets me see the other color options (accent and secondary in this example), then and only then will the apply button work. I tried messing around with focusing on grids and whatnot but that didn't seem to fix anything. Is this just some button navigation issue or can I use some tag to fix it?