private void DeleteServerMenuUI() { if (((this.Parent as ServerGroupPanel)?.Parent as ServerGroupRootPanel)?.ServerViewModel.DeleteServerGroup(this.Content.ToString()) != 0) { return; } ServerGroupRootPanel sgrp = ((this.Parent as ServerGroupPanel)?.Parent as ServerGroupRootPanel); sgrp?.DeleteChild(this.Parent as ServerGroupPanel); }
public ServerMenu() { InitializeComponent(); DataContext = new ServerViewModel(); panel_server = new ServerGroupRootPanel(); grid_server.Children.Add(panel_server); this.ContextMenu = new ContextMenu(); MenuItem item; item = new MenuItem(); item.Click += BtnAddServerMenu_Click; item.Header = "Add Server Group"; item.Icon = new PackIconMaterial() { Kind = PackIconMaterialKind.FolderPlus, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; this.ContextMenu.Items.Add(item); }
private void BtnAddServerMenu_Click(object sender, RoutedEventArgs e) { Window_AddServerMenu wms = new Window_AddServerMenu(); Point pt = this.PointToScreen(new Point(0, 0)); wms.Left = pt.X; wms.Top = pt.Y; if (wms.ShowDialog() == true) { string server_menu_name = wms.textBox_name.Text; if (((this.Parent as ServerGroupPanel)?.Parent as ServerGroupRootPanel)?.ServerViewModel.AddServerGroup(server_menu_name) != 0) { return; } ServerGroupRootPanel sgrp = ((this.Parent as ServerGroupPanel)?.Parent as ServerGroupRootPanel); sgrp?.AddChild(new ServerGroupPanel() { Content = server_menu_name }); } }