private void RecordEvent(object sender, string eventString) { DependencyObject senderAsDO = sender as DependencyObject; if (senderAsDO != null) { RecordEvent(AutomationProperties.GetAutomationId(senderAsDO) + " " + eventString); } }
protected override string GetAutomationIdCore() { string str = AutomationProperties.GetAutomationId((DependencyObject)this._adorner); if (string.IsNullOrEmpty(str)) { str = this._adorner.GetType().Name; } return(str); }
public static Transform Unwrap(UIElement element) { TransformGroup transformGroup = element.RenderTransform as TransformGroup; if (transformGroup != null && transformGroup.Children.Count > 0 && AutomationProperties.GetAutomationId((DependencyObject)transformGroup) == TransformAwareAdornerLayout.RTLAdornerTransformGroup.AutomationID) { return(transformGroup.Children[0]); } return(element.RenderTransform); }
public void WhenTheUserAcceptsTheLoginDialog() { Dispatcher.FromThread(_loginWindowThread).BeginInvoke(DispatcherPriority.Input, new Action(() => { List <Button> buttons = FindVisualChildren <Button>(_loginWindowObject).ToList(); Button okButton = buttons.First(b => AutomationProperties.GetAutomationId(b) == SQLiteArrayStore.Resources.AutomationIds.LoginDialog_OKButton); okButton.Command.Execute(null); WaitForWindowToClose(_loginWindowObject); Dispatcher.CurrentDispatcher.InvokeShutdown(); })); _loginWindowThread.Join(); }
protected override string GetAutomationIdCore() { var automationId = AutomationProperties.GetAutomationId(Owner); if (!string.IsNullOrEmpty(automationId)) { return(automationId); } if (Owner is FrameworkElement frameworkElement) { return(frameworkElement.Name); } return(base.GetAutomationIdCore()); }
/// <summary> /// Invoked when a filter is selected using a RadioButton when not snapped. /// </summary> /// <param name="sender">The selected RadioButton instance.</param> /// <param name="e">Event data describing how the RadioButton was selected.</param> void Tab_Checked(object sender, RoutedEventArgs e) { // Mirror the change into the CollectionViewSource used by the corresponding ComboBox // to ensure that the change is reflected when snapped //if (filtersViewSource.View != null) //{ // var filter = (sender as FrameworkElement).DataContext;S // filtersViewSource.View.MoveCurrentTo(filter); //} RadioButton radio = sender as RadioButton; radio.IsChecked = true; this.DefaultViewModel["Questions"] = questaoList.Where(t => t.Tab.Id == AutomationProperties.GetAutomationId(radio)); }
/// <summary> /// Finds a Child of a given item in the visual tree. /// </summary> /// <param name="parent">A direct parent of the queried item.</param> /// <typeparam name="T">The type of the queried item.</typeparam> /// <param name="childName">x:Name or Name of child. </param> /// <returns>The first parent item that matches the submitted type parameter. /// If not matching item can be found, /// a null parent is being returned.</returns> public static T FindChild <T>(DependencyObject parent, string childName) where T : DependencyObject { // Confirm parent and childName are valid. if (parent == null) { return(null); } if (string.IsNullOrEmpty(childName)) { return(null); } T foundChild = null; int childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < childrenCount; i++) { var child = VisualTreeHelper.GetChild(parent, i); // If the child is not of the request child type child T childType = child as T; var frameworkElement = child as FrameworkElement; // If the child's name is set for search if (frameworkElement != null && childType != null && AutomationProperties.GetAutomationId(frameworkElement) == childName) { // if the child's name is of the request name foundChild = (T)child; break; } else { // recursively drill down the tree foundChild = FindChild <T>(child, childName); // If the child is found, break so we do not overwrite the found child. if (foundChild != null) { break; } } } return(foundChild); }
private static void _OnAutoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (!(bool)e.NewValue) { d.ClearValue(AutomationProperties.AutomationIdProperty); return; } if (!string.IsNullOrWhiteSpace(AutomationProperties.GetAutomationId(d))) { return; } var func = _GetGenerationMethod(d); var text = func(d); if (text == null) { d.ClearValue(AutomationProperties.AutomationIdProperty); return; } AutomationProperties.SetAutomationId(d, text); }
/// <summary> /// Update the view of this visual, rebuild children as necessary /// </summary> public void Reload() { var targetFrameworkElement = target as FrameworkElement; if (targetFrameworkElement != null) { this.name = targetFrameworkElement.Name; if (string.IsNullOrEmpty(name)) { this.name = AutomationProperties.GetAutomationId(targetFrameworkElement); } } if (this.name == null) { this.name = string.Empty; } this.nameLower = (this.name ?? "").ToLower(); this.typeNameLower = this.Target != null?this.Target.GetType().Name.ToLower() : string.Empty; List <VisualTreeItem> toBeRemoved = new List <VisualTreeItem>(this.Children); this.Reload(toBeRemoved); foreach (VisualTreeItem item in toBeRemoved) { this.RemoveChild(item); } // calculate the number of visual children foreach (VisualTreeItem child in this.Children) { if (child is VisualItem) { this.visualChildrenCount++; } this.visualChildrenCount += child.visualChildrenCount; } }
public void WhenAndIsEnteredIntoTheLoginDialog(string userName, string password) { string userNameCopy = userName; string passwordCopy = password; DispatcherOperation operation = Dispatcher.FromThread(_loginWindowThread).BeginInvoke(DispatcherPriority.Input, new Action(() => { List <TextBox> textBoxes = FindVisualChildren <TextBox>(_loginWindowObject).ToList(); TextBox userNameText = textBoxes.First(t => AutomationProperties.GetAutomationId(t) == SQLiteArrayStore.Resources.AutomationIds.LoginDialog_UsernameText); TextBox passwordText = textBoxes.First(t => AutomationProperties.GetAutomationId(t) == SQLiteArrayStore.Resources.AutomationIds.LoginDialog_PasswordText); userNameText.Clear(); userNameText.Text = userNameCopy; userNameText.RaiseEvent(new RoutedEventArgs(TextBox.TextChangedEvent)); passwordText.Clear(); passwordText.Text = passwordCopy; passwordText.RaiseEvent(new RoutedEventArgs(TextBox.TextChangedEvent)); })); operation.Wait(TimeSpan.FromSeconds(1)); // allow the UI to redraw }
private void DetectLayoutElements(object sender, EventArgs e) { if (MenuBar == null) { foreach (var descendant in _mainWindow.FindDescendants <Menu>()) { if (AutomationProperties.GetAutomationId(descendant) == "MenuBar") { FrameworkElement frameworkElement = descendant; var parent = descendant.GetVisualOrLogicalParent(); if (parent != null) { frameworkElement = parent.GetVisualOrLogicalParent() as DockPanel ?? frameworkElement; } MenuBar = frameworkElement; break; } } } if (TitleBar == null) { var titleBar = _mainWindow.FindDescendants <MainWindowTitleBar>().FirstOrDefault(); if (titleBar != null) { TitleBar = titleBar; } } if (FeedbackPanel == null) { FeedbackPanel = Application.Current.MainWindow.FindElement("FrameControlContainerBorder"); } if (TitleBar != null && MenuBar != null) { _mainWindow.LayoutUpdated -= DetectLayoutElements; } }
protected string GetAutomationId(IViewHandler viewHandler) => AutomationProperties.GetAutomationId((FrameworkElement)viewHandler.NativeView);
private static TControlType?FindByUid <TControlType>(DependencyObject parent, string uid) where TControlType : DependencyObject { return(Find <TControlType>(parent, o => AutomationProperties.GetAutomationId(o) == uid || (string)o.GetValue(UIElement.UidProperty) == uid)); }
public WindowApplicationSettings(WindowSettings windowSettings) : base(AutomationProperties.GetAutomationId(windowSettings._window)) { }
protected override string?GetAutomationIdCore() => AutomationProperties.GetAutomationId(Owner) ?? Owner.Name;
private void UpdateScrollmap() { if (logItemsHostPanel == null) { // SmoothVirtualizingPanel_Loaded wasn't called yet. Remember to update the scroll // map when it will be called. scrollmapUpdatePending = true; return; } if (logItemsScroll == null) { return; } bool showWarningsErrors = App.Settings.ShowWarningsErrorsInScrollBar; bool showSelection = App.Settings.ShowSelectionInScrollBar; if (!showWarningsErrors && !showSelection) { // Nothing to display, but clear anything that may already be there ClearScrollmap(); return; } double itemOffset = 0; double itemHeight = logItemsHostPanel.ItemHeight; bool scrollBarVisible = logItemsScroll.ComputedVerticalScrollBarVisibility == Visibility.Visible; if (scrollBarVisible) { ScrollBar sb = logItemsScroll.FindVisualChild <ScrollBar>(d => AutomationProperties.GetAutomationId(d) == "VerticalScrollBar"); if (sb != null) { Grid g = sb.FindVisualChild <Grid>(); if (g != null && g.RowDefinitions.Count == 3) { itemOffset = g.RowDefinitions[0].ActualHeight + 2; itemHeight = (g.RowDefinitions[1].ActualHeight - 4) / LogItemsList.Items.Count; } } } else { return; } StreamGeometry warningGeometry = new StreamGeometry(); warningGeometry.FillRule = FillRule.Nonzero; StreamGeometry errorGeometry = new StreamGeometry(); errorGeometry.FillRule = FillRule.Nonzero; StreamGeometry criticalGeometry = new StreamGeometry(); criticalGeometry.FillRule = FillRule.Nonzero; StreamGeometry selectionGeometry = new StreamGeometry(); selectionGeometry.FillRule = FillRule.Nonzero; StreamGeometryContext warningCtx = warningGeometry.Open(); StreamGeometryContext errorCtx = errorGeometry.Open(); StreamGeometryContext criticalCtx = criticalGeometry.Open(); StreamGeometryContext selectionCtx = selectionGeometry.Open(); HashSet <object> selectedItems = new HashSet <object>(LogItemsList.SelectedItems.OfType <object>()); for (int index = 0; index < LogItemsList.Items.Count; index++) { if (showWarningsErrors) { FieldLogItemViewModel flItem = LogItemsList.Items[index] as FieldLogItemViewModel; if (flItem != null) { if (flItem.Priority >= FieldLogPriority.Warning) { double y = Math.Round(itemOffset + (index + 0.5) * itemHeight); StreamGeometryContext ctx; if (flItem.Priority == FieldLogPriority.Warning) { ctx = warningCtx; } else if (flItem.Priority == FieldLogPriority.Error) { ctx = errorCtx; } else if (flItem.Priority == FieldLogPriority.Critical) { ctx = criticalCtx; } else { continue; } ctx.BeginFigure(new Point(0, y - 2), true, true); ctx.PolyLineTo(new Point[] { new Point(3, y - 2), new Point(3, y + 2), new Point(0, y + 2) }, false, false); } } } if (showSelection) { if (selectedItems.Contains(LogItemsList.Items[index])) { double y = Math.Round(itemOffset + (index + 0.5) * itemHeight); selectionCtx.BeginFigure(new Point(4, y - 1), true, true); selectionCtx.PolyLineTo(new Point[] { new Point(7, y - 1), new Point(7, y + 1), new Point(4, y + 1) }, false, false); } } } warningCtx.Close(); warningGeometry.Freeze(); errorCtx.Close(); errorGeometry.Freeze(); criticalCtx.Close(); criticalGeometry.Freeze(); selectionCtx.Close(); selectionGeometry.Freeze(); WarningMap.Data = warningGeometry; ErrorMap.Data = errorGeometry; CriticalMap.Data = criticalGeometry; SelectionMap.Data = selectionGeometry; }
public static T FindByAutomationId <T>(Window window, string automationId) where T : DependencyObject { return(EnumerateVisualTree(window).OfType <T>().Single(i => AutomationProperties.GetAutomationId(i) == automationId)); }
/// protected override string GetAutomationIdCore() { return(AutomationProperties.GetAutomationId(_owner)); }
/// <summary> /// Finds a Child of a given item in the visual tree. /// </summary> /// <param name="parent">A direct parent of the queried item.</param> /// <typeparam name="T">The type of the queried item.</typeparam> /// <param name="childName">x:Name or Name of child. </param> /// <param name="findIndex">the index of the item to be found. 0 to find the first name/type match, 1 to find the second match, etc </param> /// <param name="foundCount">recursion counter to keep track of the number of name/type matches found so far. </param> /// <returns>The first parent item that matches the submitted type parameter. /// If not matching item can be found, a null parent is being returned.</returns> static T FindChild <T>(DependencyObject parent, string childName, int findIndex, ref int foundCount) where T : DependencyObject { //Confirm parent and childName are valid. if (parent == null) { return(null); } var foundChild = default(T); var childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < childrenCount; i++) { var child = VisualTreeHelper.GetChild(parent, i); // If the child is not of the request child type child var childType = child as T; if (childType == null) { //Recursively drill down the tree foundChild = FindChild <T>(child, childName, findIndex, ref foundCount); //If the child is found, break so we do not overwrite the found child. if (foundChild != null) { break; } } else if (!string.IsNullOrEmpty(childName)) { var frameworkElement = child as FrameworkElement; //If the child's name is set for search if (frameworkElement != null && (frameworkElement.Name == childName || AutomationProperties.GetAutomationId(frameworkElement) == childName)) { //If the child's name is of the request name if (foundCount == findIndex) { foundChild = (T)child; break; } else { foundCount++; } } else { //Recursively drill down the tree foundChild = FindChild <T>(child, childName, findIndex, ref foundCount); //If the child is found, break so we do not overwrite the found child. if (foundChild != null) { break; } } } else { //Child element found. foundChild = (T)child; break; } } return(foundChild); }