Need to press some other button before button works in WPF

bnzzy_ 1 Reputation point
2021-10-13T04:38:47.687+00:00

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?

Developer technologies | Windows Presentation Foundation
Developer technologies | XAML
Developer technologies | XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.