protected override bool TranslateAcceleratorCore(ref MSG msg, ModifierKeys modifiers) { if (msg.message == WindowMessages.WM_KEYDOWN && msg.wParam.ToInt32() == VirtualKeyCodes.VK_TAB) { object currentlyFocusedElement = Windows.UI.Xaml.Input.FocusManager.GetFocusedElement(); if (ModifierKeys.Shift == modifiers) { Windows.UI.Xaml.DependencyObject firstFocusableElement = Windows.UI.Xaml.Input.FocusManager.FindFirstFocusableElement(null); if (currentlyFocusedElement == firstFocusableElement) { bool focusDeparted = ((IKeyboardInputSink)this).KeyboardInputSite.OnNoMoreTabStops(new TraversalRequest(FocusNavigationDirection.Previous)); if (focusDeparted) { // need xaml to lose focus Windows.UI.Xaml.Controls.Control currentlyFocusedControl = (Windows.UI.Xaml.Controls.Control)currentlyFocusedElement; currentlyFocusedControl.IsTabStop = false; currentlyFocusedControl.IsEnabled = false; currentlyFocusedControl.IsTabStop = true; currentlyFocusedControl.IsEnabled = true; } return(focusDeparted); } return(Windows.UI.Xaml.Input.FocusManager.TryMoveFocus(Windows.UI.Xaml.Input.FocusNavigationDirection.Previous)); } else { Windows.UI.Xaml.DependencyObject lastFocusableElement = Windows.UI.Xaml.Input.FocusManager.FindLastFocusableElement(null); if (currentlyFocusedElement == lastFocusableElement) { bool focusDeparted = ((IKeyboardInputSink)this).KeyboardInputSite.OnNoMoreTabStops(new TraversalRequest(FocusNavigationDirection.Next)); if (focusDeparted) { // need xaml to lose focus Windows.UI.Xaml.Controls.Control currentlyFocusedControl = (Windows.UI.Xaml.Controls.Control)currentlyFocusedElement; currentlyFocusedControl.IsTabStop = false; currentlyFocusedControl.IsEnabled = false; currentlyFocusedControl.IsTabStop = true; currentlyFocusedControl.IsEnabled = true; } return(focusDeparted); } return(Windows.UI.Xaml.Input.FocusManager.TryMoveFocus(Windows.UI.Xaml.Input.FocusNavigationDirection.Next)); } } return(false); }
/// <summary> /// The go to state core. /// </summary> /// <param name="control"> /// The control. /// </param> /// <param name="templateRoot"> /// The template root. /// </param> /// <param name="stateName"> /// The state name. /// </param> /// <param name="group"> /// The group. /// </param> /// <param name="state"> /// The state. /// </param> /// <param name="useTransitions"> /// The use transitions. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> protected override bool GoToStateCore( Windows.UI.Xaml.Controls.Control control, FrameworkElement templateRoot, string stateName, VisualStateGroup group, VisualState state, bool useTransitions) { Debug.WriteLine( "Custom: {0} with template root {1} going to state {2}", control.GetType().FullName, templateRoot.GetType().FullName, stateName); return(base.GoToStateCore(control, templateRoot, stateName, group, state, useTransitions)); }
public object BindAndActiveViewModel(Windows.UI.Xaml.Controls.Control view) { var viewModel = ViewModelLocator.LocateForViewType(view.GetType()); if (viewModel == null) { return(null); } ViewModelBinder.Bind(viewModel, view, null); var activate = viewModel as IActivate; if (activate != null) { activate.Activate(); } return(viewModel); }
/// <summary> /// This method is used to wrap the Windows.UI.Xaml control in a new instance of a WindowsXamlHost. /// </summary> /// <param name="windowsXamlHost"></param> /// <param name="control"></param> /// <returns>Control</returns> internal Control WrapInXamlHost(WindowsXamlHost windowsXamlHost, WUX.Controls.Control control) { windowsXamlHost.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly; windowsXamlHost.InitialTypeName = null; windowsXamlHost.Padding = new Padding(5); WUX.Controls.StackPanel stackPanel = new WUX.Controls.StackPanel() { HorizontalAlignment = WUX.HorizontalAlignment.Stretch }; stackPanel.Children.Add(control); windowsXamlHost.Child = stackPanel; if (windowsXamlHost.Width == 0) { windowsXamlHost.Height = ((int)control.Height > 0) ? (int)control.Height + 100 : 80; windowsXamlHost.Width = ((int)control.Width > 0) ? (int)control.Width + 220 : 500; } return(windowsXamlHost); }
internal static Windows.UI.Xaml.Controls.Control FindControl(Windows.UI.Xaml.DependencyObject root, String name) { var count = Windows.UI.Xaml.Media.VisualTreeHelper.GetChildrenCount(root); for (int i = 0; i < count; i++) { var child = Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(root, i); var childControl = child as Windows.UI.Xaml.Controls.Control; if (childControl != null) { if (childControl.Name == name) { return(childControl); } } Windows.UI.Xaml.Controls.Control found = FindControl(child, name); if (found != null && found.Name == name) { return(found); } } return(null); }
static void UnfocusNativeControl(Windows.UI.Xaml.Controls.Control control) { if (control == null) { return; } // "Unfocusing" doesn't really make sense on Windows; for accessibility reasons, // something always has focus. So forcing the unfocusing of a control would normally // just move focus to the next control, or leave it on the current control if no other // focus targets are available. This is what happens if you use the "disable/enable" // hack. What we *can* do is set the focus to the Page which contains Control; // this will cause Control to lose focus without shifting focus to, say, the next Entry // Work our way up the tree to find the containing Page DependencyObject parent = control as Windows.UI.Xaml.Controls.Control; while (parent != null && !(parent is Windows.UI.Xaml.Controls.Page)) { parent = Windows.UI.Xaml.Media.VisualTreeHelper.GetParent(parent); } if (parent is Windows.UI.Xaml.Controls.Page _containingPage) { // Cache the tabstop setting // var wasTabStop = _containingPage.IsTabStop; // Controls can only get focus if they're a tabstop _containingPage.IsTabStop = true; _containingPage.Focus(FocusState.Programmatic); // Restore the tabstop setting; that may cause the Page to lose focus, // but it won't restore the focus to Control //_containingPage.IsTabStop = wasTabStop; } }
public PageOptionsControl(Windows.UI.Xaml.Controls.Control control) { this._TargetControl = control; control.SizeChanged += Control_SizeChanged; }