private void SaveFigBtn_Click(object sender, RoutedEventArgs e) { List <Shape> customList = new List <Shape>(); for (int i = 0; i < shapesWindow.shapesBox.Items.Count; i++) { if ((shapesWindow.shapesBox.Items[i] as ShapePropertyControl).shape != null) { customList.Add((shapesWindow.shapesBox.Items[i] as ShapePropertyControl).shape); } else { customList.AddRange((shapesWindow.shapesBox.Items[i] as ShapePropertyControl).custom.list); } } CustomFigure custom = new CustomFigure(customList); cnv.Children.Clear(); shapesWindow.shapesBox.Items.Clear(); custom.Draw(cnv); customFigList.Add(custom); shapesWindow.shapesBox.Items.Add(new ShapePropertyControl(custom)); shapesWindow.shapesBox.SelectedIndex = shapesWindow.shapesBox.Items.Count - 1; }
public ShapePropertyControl(CustomFigure shape) { InitializeComponent(); custom = shape; Name.Text = "Custom"; Height.Text = shape.Height.ToString(); Width.Text = shape.Width.ToString(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { void reposWindow(Window w) { w.Left = this.Left + this.Width; w.Top = this.Top; } void changeHeight(Window w) { w.Height = this.Height; reposWindow(w); } shapesWindow = new ShapesWindow { Width = 300, Owner = this, }; reposWindow(shapesWindow); shapesWindow.Show(); this.LocationChanged += (s, _) => reposWindow(shapesWindow); this.SizeChanged += (s, _) => changeHeight(shapesWindow); ResourceDictionary rd = new ResourceDictionary() { Source = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml") }; Resources.MergedDictionaries.Add(rd); rd = new ResourceDictionary() { Source = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml") }; Resources.MergedDictionaries.Add(rd); rd = new ResourceDictionary() { Source = new Uri("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Teal.xaml") }; Resources.MergedDictionaries.Add(rd); rd = new ResourceDictionary() { Source = new Uri("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml") }; Resources.MergedDictionaries.Add(rd); settingsWindow = new SettingsWindow(this); XmlDocument doc = new XmlDocument(); try { doc.Load("config.xml"); XmlElement element = doc.DocumentElement; XmlNode node = element["isLightTheme"]; Resources.MergedDictionaries[0] = new ResourceDictionary(); if (Convert.ToBoolean(node.InnerText)) { settingsWindow.themeToggle.IsChecked = true; } else { settingsWindow.themeToggle.IsChecked = false; shapeComboBox.Foreground = new SolidColorBrush(Colors.White); xy.Foreground = new SolidColorBrush(Colors.White); } node = element["AccentColor"]; Resources.MergedDictionaries[2] = new ResourceDictionary { Source = new Uri(node.InnerText) }; } catch (Exception ex) { MessageBox.Show(ex.Message); } if (File.Exists(Directory.GetCurrentDirectory() + "\\custom.json")) { List <Shape> objList = new List <Shape>(); DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(objList.GetType(), typeList.ToArray()); using (FileStream fStream = new FileStream(Directory.GetCurrentDirectory() + "\\custom.json", FileMode.Open)) { try { objList = jsonSerializer.ReadObject(fStream) as List <Shape>; } catch (Exception ex) { } } List <Shape> customList = new List <Shape>(); CustomFigure custom = new CustomFigure(objList); custom.Draw(cnv); //customFigList.Add(custom); shapesWindow.shapesBox.Items.Add(new ShapePropertyControl(custom)); shapesWindow.shapesBox.SelectedIndex = shapesWindow.shapesBox.Items.Count - 1; } }