I am designing a simple application in C# and WPF with multiple buttons that change their color when clicked.
Each individual button changes colors independently to red (1st click) and then to green (on the 2nd click).
I am looking for a way to make this changes persistent between application runs. In other words, if 1 button has been set to green and 1 button to red, I would like them to keep their color (unless i change it) regardless of how many times I open and close the application. Examples of code that i can use are more than welcomed. Any help or example of code is highly appreciated. Thank you!
This is the WPF:
<Button x:Name="btn0" Focusable="False" Margin="277,100,173,148" Click="btn0_Click" Content="access"/>
<Button x:Name="btn1" Focusable="False" Margin="189,100,253,148" Click="btn1_Click" Content="access"/>
And here is the code (i know it's a bit messy):
namespace WpfApp7
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private bool _IsOn;
public bool IsOn
{
get
{
return _IsOn;
}
set
{
_IsOn = value;
btn0.Background = _IsOn ? Brushes.Green : Brushes.Red;
}
}
private void btn0_Click(object sender, RoutedEventArgs e)
{
IsOn = !IsOn;
}
private bool _IsOn1;
public bool IsOn1
{
get
{
return _IsOn1;
}
set
{
_IsOn1 = value;
btn1.Background = _IsOn1 ? Brushes.Green : Brushes.Red;
}
}
private void btn1_Click(object sender, RoutedEventArgs e)
{
IsOn1 = !IsOn1;
}
}
}