private void load_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "dat files (*.dat)|*.dat"; dialog.ShowDialog(); string path = dialog.FileName; if (path.Equals("")) { return; } using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate)) { StreamReader sr = new StreamReader(fs); MyStyle style = (MyStyle)XamlReader.Parse(sr.ReadToEnd()); sideLeft.chageColor(style.fontColor, style.backgroundColor); sideRight.chageColor(style.fontColor, style.backgroundColor); sideLeft.changeFont(style.fontSize); sideRight.changeFont(style.fontSize); } }
private void save_Click(object sender, RoutedEventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "dat files (*.dat)|*.dat"; dialog.ShowDialog(); string path = dialog.FileName; if (path.Equals("")) { return; } using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate)) { MyStyle style = new MyStyle(); if (fontColor == null || backgroundColor == null) { style.fontColor = Brushes.Blue; style.backgroundColor = (SolidColorBrush) new BrushConverter().ConvertFrom("#FFE3F8FF"); } else { style.fontColor = fontColor; style.backgroundColor = backgroundColor; } if (fontSize < 10 || fontSize > 20) { style.fontSize = 15; } else { style.fontSize = fontSize; } string styleStr = XamlWriter.Save(style); StreamWriter sw = new StreamWriter(fs); sw.Write(styleStr); sw.Close(); fs.Close(); } }