/// <summary> /// Set focus on the first valid focusable element in the control /// </summary> public void SetFocus(object dataContext = null) { UIElement focus = null; if (IsEnabled && Focusable) { focus = this; } else { if (dataContext != null) { focus = WPF.FindFirstChild <FrameworkElement>(this, (wx) => wx.IsVisible && wx.IsEnabled && wx.Focusable && wx.DataContext == dataContext ); } if (focus == null) { focus = WPF.FindFirstChild <UIElement>(this, (wx) => wx.IsVisible && wx.IsEnabled && wx.Focusable ); } } LimeMsg.Debug("LimeControl SetFocus: {0}", focus); if (focus != null) { Keyboard.Focus(focus); } }
private void Popup_Opened(object sender, EventArgs e) { LimeMsg.Debug("Popup_Opened"); // Subscribe to every parent scrollviewers to detect scrolling there (and close the DropDown) if (_ScrollChangedEventHandler == null) { _ScrollChangedEventHandler = new ScrollChangedEventHandler(ScrollViewer_ScrollChanged); foreach (var scrollViewer in GetParentScrollViewers()) { scrollViewer.ScrollChanged += _ScrollChangedEventHandler; } } // Autosize if (wxPopup.Placement == PlacementMode.Bottom || wxPopup.Placement == PlacementMode.Top) { wxPopupBorder.MinWidth = wxMain.ActualWidth; wxPopup.HorizontalOffset = wxMain.Margin.Left; } var item = WPF.FindFirstChild <TextBox>(wxPicker); if (item != null) { Keyboard.Focus(item); } }
private void ListBox_PreviewKeyDown(object sender, KeyEventArgs e) { LimeMsg.Debug("ListBox_PreviewKeyDown: {0}", e.Key); var wxobj = e.OriginalSource as ListBoxItem; if (wxobj == null) { return; } if (Keyboard.Modifiers != 0) { return; } bool close = false; switch (e.Key) { case Key.Enter: var wxcheck = WPF.FindFirstChild <CheckBox>(wxobj); if (wxcheck != null) { wxcheck.IsChecked = !wxcheck.IsChecked; e.Handled = true; } else { close = true; } break; case Key.Escape: var prop = wxMain.DataContext as LimeProperty; Cache = prop.Value; close = true; break; case Key.Up: close = wxMenu.SelectedIndex == 0; break; case Key.Right: case Key.Left: close = true; break; } if (close) { wxPopup.IsOpen = false; wxMain.IsChecked = false; Keyboard.Focus(wxMain); e.Handled = true; } }
private void Popup_Opened(object sender, EventArgs e) { LimeMsg.Debug("Popup_Opened"); // Subscribe to every parent scrollviewers to detect scrolling there (and close the DropDown) if (_ScrollChangedEventHandler == null) { _ScrollChangedEventHandler = new ScrollChangedEventHandler(ScrollViewer_ScrollChanged); foreach (var scrollViewer in GetParentScrollViewers()) { LimeMsg.Debug("LimeDropDown Popup_Opened: subscribe _ScrollChangedEventHandler: {0}", scrollViewer); scrollViewer.ScrollChanged += _ScrollChangedEventHandler; } } // Autosize if (wxPopup.Placement == PlacementMode.Bottom || wxPopup.Placement == PlacementMode.Top) { wxMenu.MinWidth = wxMain.ActualWidth; wxPopup.HorizontalOffset = wxMain.Margin.Left; } // Readjust value if not yet selected if (wxMenu.ItemsSource != null && Cache != null) { wxMenu.SelectedValue = Cache; } ListBoxItem item = null; if (wxMenu.SelectedItem != null) { item = wxMenu.ItemContainerGenerator.ContainerFromItem(wxMenu.SelectedItem) as ListBoxItem; } if (item == null) { item = WPF.FindFirstChild <ListBoxItem>(wxMenu); } if (item != null) { Keyboard.Focus(item); } }
private static void OnOptionsEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (!(d is LimeControl wxThis)) { return; } var prop = wxThis.DataContext as LimeProperty; if (wxThis.MainGrid != null && prop != null) { var wxobj = WPF.FindFirstChild <StackPanel>(wxThis.MainGrid); wxobj.Children.Clear(); if ((bool)e.NewValue) { if (prop.ReqAdmin) { wxobj.Children.Add(new LimeIcon() { IconKey = "Shield", ToolTip = LimeLanguage.Translate(LanguageSection, "ShieldTip", "ShieldTip") }); } if (prop.ReqRestart) { wxobj.Children.Add(new LimeIcon() { IconKey = "Warning", ToolTip = LimeLanguage.Translate(LanguageSection, "RestartTip", "RestartTip") }); } } } wxThis.OnOptionsEnabledPropertyChanged(e); }