void AssociatedObjectFocus() { if (AssociatedObject.Focusable && AssociatedObject.IsTabStop) { AssociatedObject.Focus(); } else { var children = LayoutTreeHelper.GetVisualChildren(AssociatedObject); var controlToFocus = children.OfType <Control>().Where(x => x.Focusable && x.IsTabStop).FirstOrDefault(); controlToFocus.Do(x => x.Focus()); } }
internal static void UpdateWindowOwner(Window w, FrameworkElement ownerObject) { if (ownerObject == null) { return; } if (!ViewModelBase.IsInDesignMode) { w.Owner = LayoutTreeHelper.GetVisualParents(ownerObject).OfType <Window>().FirstOrDefault() ?? Window.GetWindow(ownerObject); } else { System.Windows.Interop.WindowInteropHelper windowInteropHelper = new System.Windows.Interop.WindowInteropHelper(w); windowInteropHelper.Owner = GetActiveWindow(); } }
protected virtual FrameworkElement FindParent(object sender, DependencyObject originalSource) { return(LayoutTreeHelper.GetVisualParents(originalSource, (DependencyObject)sender).Where(CheckItemType(sender)).FirstOrDefault() as FrameworkElement); }