private void OnWindowClosed(object sender, EventArgs e) { ColorSettings settings = new ColorSettings(textColorPicker.SelectedColor, backgroundColorPicker.SelectedColor); using (Stream stream = new FileStream("color.config", FileMode.OpenOrCreate)) { BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(stream, settings); } }
private void OnLoadedWindow(object sender, RoutedEventArgs e) { ColorSettings settings; using (Stream stream = new FileStream("color.config", FileMode.OpenOrCreate)) { BinaryFormatter serializer = new BinaryFormatter(); try { settings = (ColorSettings)serializer.Deserialize(stream); } catch { settings = new ColorSettings(null, null); } } textColorPicker.SelectedColor = settings.TextColor; backgroundColorPicker.SelectedColor = settings.BackgroundColor; textColorChanged(null, null); BackgroundColorChanged(null, null); }