private void openMenu( ) { if (expanded) { return; } if (this.Type == MenuItemType.Submenu || Type == MenuItemType.RootSubmenu) { if (null == popup) { popup = new Popup(this.Items, this.popupShadow, this.ActualWidth); foreach (MenuItemBase itemBase in this.Items) { if (itemBase is MenuItem) { (( MenuItem )itemBase).ParentItem = this; } } popup.AddHandler(Window.ClosedEvent, new EventHandler(onPopupClosed)); } WindowsHost windowsHost = VisualTreeHelper.FindClosestParent <WindowsHost>(this); Point point = TranslatePoint(this, new Point(0, 0), windowsHost); popup.X = point.X; popup.Y = point.Y; windowsHost.ShowModal(popup, true); expanded = true; } }
private void openPopup( ) { if (opened) { throw new InvalidOperationException("Assertion failed."); } Window popup = new PopupWindow(Items, SelectedItemIndex ?? 0, shadow, ShownItemsCount != null ? ShownItemsCount.Value - 1 : ( int? )null); Point popupCoord = TranslatePoint(this, new Point(0, 0), VisualTreeHelper.FindClosestParent <WindowsHost>(this)); popup.X = popupCoord.X; popup.Y = popupCoord.Y; popup.Width = shadow ? ActualWidth + 1 : ActualWidth; if (Items.Count != 0) { popup.Height = (ShownItemsCount != null ? ShownItemsCount.Value : Items.Count) + (shadow ? 2 : 1); // 1 row for transparent "header" } else { popup.Height = shadow ? 3 : 2; } WindowsHost windowsHost = VisualTreeHelper.FindClosestParent <WindowsHost>(this); windowsHost.ShowModal(popup, true); opened = true; EventManager.AddHandler(popup, Window.ClosedEvent, new EventHandler(OnPopupClosed)); }
public void OpenMenu(WindowsHost windowsHost, Point point) { if (expanded) { return; } // Вешаем на WindowsHost обработчик события MenuItem.ClickEvent, // чтобы ловить момент выбора пункта меню в одном из модальных всплывающих окошек // Дело в том, что эти окошки не являются дочерними элементами контрола Menu, // а напрямую являются дочерними элементами WindowsHost (т.к. именно он создаёт // окна). И событие выбора пункта меню из всплывающего окошка может быть поймано // в WindowsHost, но не в Menu. А нам нужно повесить обработчик, который закроет // все показанные попапы. EventManager.AddHandler(windowsHost, MenuItem.ClickEvent, windowsHostClick = (sender, args) => { CloseAllSubmenus( ); popup.Close( ); }, true); EventManager.AddHandler(windowsHost, MenuItem.Popup.ControlKeyPressedEvent, windowsHostControlKeyPressed = (sender, args) => { CloseAllSubmenus( ); // //ConsoleApplication.Instance.FocusManager.SetFocusScope(this); if (args.wVirtualKeyCode == VirtualKeys.Right) { ConsoleApplication.Instance.FocusManager.MoveFocusNext( ); } else if (args.wVirtualKeyCode == VirtualKeys.Left) { ConsoleApplication.Instance.FocusManager.MoveFocusPrev( ); } MenuItem focusedItem = ( MenuItem )this.Items.SingleOrDefault( item => item is MenuItem && item.HasFocus); focusedItem.Expand( ); }); if (null == popup) { popup = new MenuItem.Popup(this.Items, this.popupShadow, 0); popup.AddHandler(Window.ClosedEvent, new EventHandler(onPopupClosed)); } popup.X = point.X; popup.Y = point.Y; windowsHost.ShowModal(popup, true); expanded = true; this.windowsHost = windowsHost; }
public static void Show(string title, string text, MessageBoxClosedEventHandler onClosed) { Control rootControl = ConsoleApplication.Instance.RootControl; if (!(rootControl is WindowsHost)) { throw new InvalidOperationException("Default windows host not found, create MessageBox manually"); } WindowsHost windowsHost = ( WindowsHost )rootControl; MessageBox messageBox = new MessageBox( ); messageBox.Title = title; messageBox.Text = text; messageBox.AddHandler(ClosedEvent, new EventHandler((sender, args) => { onClosed(MessageBoxResult.Button1); })); //messageBox.X = windowsHost.ShowModal(messageBox); }
public void OpenMenu( WindowsHost windowsHost, Point point ) { if ( expanded ) return; // Вешаем на WindowsHost обработчик события MenuItem.ClickEvent, // чтобы ловить момент выбора пункта меню в одном из модальных всплывающих окошек // Дело в том, что эти окошки не являются дочерними элементами контрола Menu, // а напрямую являются дочерними элементами WindowsHost (т.к. именно он создаёт // окна). И событие выбора пункта меню из всплывающего окошка может быть поймано // в WindowsHost, но не в Menu. А нам нужно повесить обработчик, который закроет // все показанные попапы. EventManager.AddHandler( windowsHost, MenuItem.ClickEvent, windowsHostClick = ( sender, args ) => { CloseAllSubmenus( ); popup.Close( ); }, true ); EventManager.AddHandler( windowsHost, MenuItem.Popup.ControlKeyPressedEvent, windowsHostControlKeyPressed = ( sender, args ) => { CloseAllSubmenus( ); // //ConsoleApplication.Instance.FocusManager.SetFocusScope(this); if ( args.wVirtualKeyCode == VirtualKeys.Right ) ConsoleApplication.Instance.FocusManager.MoveFocusNext( ); else if ( args.wVirtualKeyCode == VirtualKeys.Left ) ConsoleApplication.Instance.FocusManager.MoveFocusPrev( ); MenuItem focusedItem = ( MenuItem ) this.Items.SingleOrDefault( item => item is MenuItem && item.HasFocus ); focusedItem.Expand( ); } ); if ( null == popup ) { popup = new MenuItem.Popup( this.Items, this.popupShadow, 0 ); popup.AddHandler( Window.ClosedEvent, new EventHandler( onPopupClosed ) ); } popup.X = point.X; popup.Y = point.Y; windowsHost.ShowModal( popup, true ); expanded = true; this.windowsHost = windowsHost; }