I have a WPF GUI that allows the user to open up an options menu. The option menu opens in a new window and is filled with check boxes. When the user presses the "ok" button the window closes. However, it doesn't remember what check boxes were checked when it is opened back up. How do I make sure the program is able to remember what boxes were checked and which ones weren't?
Just to specify: I only need to remember which boxes are checked during the run of the program. The program does not need to remember after the entire program has been exited.
Thanks!
Here is my code under the main window Window1.XAML.CS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CartToolsPrototype1
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
//Exit
private void Exit_Click(object sender, RoutedEventArgs e)
{
System.Environment.Exit(0);
}
//Options
private void Options_Click(object sender, RoutedEventArgs e)
{
var newWindow = new Options();
newWindow.Show();
}
}
}
Here is my code under the child Window Options.XAML.CS. This is based off of the first answer. I've read through the link you posted and it makes sense. I have conditions in my settings file that I change when the user checks my check boxes. I then have a condition that determines whether the box is checked based on the settings file, but it doesn't seem to reflect any change...
public partial class Options_Window : Window
{
public Options_Window()
{
InitializeComponent();
//Checkbox1
if (Properties.Settings.Default.OptionsBox1 == true)
checkBox1.IsChecked = true;
else
checkBox1.IsChecked = false;
}
//Close Window
private void button1_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
//Ask before downloading... - CHECKED
private void checkBox1_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.OptionsBox1 = true;
}
//Ask before downloading... - UNCHECKED
private void checkBox1_Unchecked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.OptionsBox1 = false;
}