Reputation: 2106
I have a uwp app and I've add two Radio Buttons for change theme from black to white
but I couldn't change the check using isChecked
everytime my app crash and close
Here's my Code
if (localSettings.Values["Theme"] != null)
{
string R = localSettings.Values["Theme"].ToString();
if (R == "light")
{
RequestedTheme = ElementTheme.Light;
white.IsChecked = true;
black.IsChecked = false;
}
else
{
RequestedTheme = ElementTheme.Dark;
black.IsChecked = true;
}
}
else
{
RequestedTheme = ElementTheme.Dark;
black.IsChecked = true;
white.IsChecked = false;
}
Picture
Upvotes: 0
Views: 1239
Reputation: 35
You are trying to use something that is null. This means you either set it to null, or you never set it to anything at all. In your case, it is the check box called Black. You can solve the app crashing and closing issue by handling the null value. In addition, you can display the error as a message by inserting try and catch block in order to solve the issue of crashing and closing apps. Show more code for black and white checkbox in order to help you with more specifically.
Upvotes: 0
Reputation: 12761
Your form (XAML) which contains the radio button is not initialized.
Ensure you do set values to your controls once InitializeComponent()
function is called for your form.
Upvotes: 2