private void button1_Click(object sender, RoutedEventArgs e) { component = new ShapeConnectors.Component(); component.Name = textBox1.Text; foreach (var item in items) { component.Items.Add(new ShapeConnectors.ComponentItem(item.tb.Text, item.tbtype.Text)); } }
private void AddComponentToTreeView(Component component) { string filename = "Images\\Component.png"; Image img = new Image(); Label lb1 = new Label(); LoadedComponents.Add(component.Name, component); img.Tag = component.Name + "Component"; lb1.Content = component.Name; BitmapImage src = new BitmapImage(); src.BeginInit(); src.UriSource = new Uri(filename, UriKind.Relative); src.EndInit(); StackPanel stk1 = new StackPanel(); img.Source = src; img.Width = 50; img.Height = 30; img.Margin = new Thickness(10); img.MouseLeftButtonDown += ListViewItem_MouseLeftButtonDown; stk1.Children.Add(img); stk1.Children.Add(lb1); listView1.Items.Add(stk1); }
private void listView1_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { //Do work. Can special-case logic based on Copy, Move, etc. string[] fileNames = e.Data.GetData(DataFormats.FileDrop, true) as string[]; foreach (var item in fileNames) { string filename=""; Component cc = new Component(); Tag tt = new Tag(); Label lb1 = new Label(); lb1.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; Image img = new Image(); if (item.Contains("Component")) { filename="Images\\Component.png"; cc = DeserializeComponent(item); LoadedComponents.Add(cc.Name, cc); img.Tag = cc.Name+"Component"; lb1.Content= cc.Name; } else if (item.Contains("Tag")) { filename = "Images\\Tag.png"; tt = DeserializeTag(item); img.Tag = tt.Name + "Tag"; lb1.Content = tt.Name; } if ( filename.Length>0) { BitmapImage src = new BitmapImage(); src.BeginInit(); src.UriSource = new Uri(filename, UriKind.Relative); src.EndInit(); StackPanel stk1 = new StackPanel(); img.Source = src; img.Width = 50; img.Height = 30; img.Margin = new Thickness(10); img.MouseLeftButtonDown += ListViewItem_MouseLeftButtonDown; stk1.Children.Add(img); stk1.Children.Add(lb1); listView1.Items.Add(stk1); } } } e.Handled = true; }