public ChainViewer(Chain chain, bool backgroundBorder = false) { InitializeComponent(); _chain = chain; _chain.Viewer = this; DeviceContextMenuBefore = (ContextMenu)this.Resources["DeviceContextMenuBefore"]; DeviceContextMenuBefore.AddHandler(MenuItem.ClickEvent, DeviceContextMenu_Click); DeviceContextMenuAfter = (ContextMenu)this.Resources["DeviceContextMenuAfter"]; DeviceContextMenuAfter.AddHandler(MenuItem.ClickEvent, DeviceContextMenu_Click); this.AddHandler(DragDrop.DropEvent, Drop); this.AddHandler(DragDrop.DragOverEvent, DragOver); for (int i = 0; i < _chain.Count; i++) { Contents_Insert(i, _chain[i]); } if (backgroundBorder) { this.Get <Grid>("Root").Children.Insert(0, new DeviceBackground()); Background = (IBrush)Application.Current.Styles.FindResource("ThemeControlDarkenBrush"); } }
private void Unloaded(object sender, VisualTreeAttachmentEventArgs e) { _chain.Viewer = null; _chain = null; DeviceContextMenuBefore.RemoveHandler(MenuItem.ClickEvent, DeviceContextMenu_Click); DeviceContextMenuAfter.RemoveHandler(MenuItem.ClickEvent, DeviceContextMenu_Click); DeviceContextMenuBefore = DeviceContextMenuAfter = null; this.RemoveHandler(DragDrop.DropEvent, Drop); this.RemoveHandler(DragDrop.DragOverEvent, DragOver); }
private void Click(object sender, PointerReleasedEventArgs e) { if (e.MouseButton == MouseButton.Right) { if (sender == DropZoneBefore) { DeviceContextMenuBefore.Open((Control)sender); } else if (sender == DropZoneAfter) { DeviceContextMenuAfter.Open((Control)sender); } } e.Handled = true; }