internal static DependencyObject GetParentInternal(DependencyObject reference) { Visual visual; Visual3D visual3D; VisualTreeUtils.AsVisualInternal(reference, out visual, out visual3D); if (visual != null) { return(visual.InternalVisualParent); } if (visual3D != null) { return(visual3D.InternalVisualParent); } Debug.Assert(reference == null); return(null); }
public object OnItemsCopied(List <ModelItem> itemsToCopy) { itemsToCopy.Remove(this.initialModelItem); // If the item copied is Transition, save its destination state guid to find the destination state when pasting. if (itemsToCopy.Count == 1) { ModelItem item = itemsToCopy.First(); if (item != null && item.ItemType == typeof(Transition)) { ModelItem destinationState = item.Properties[TransitionDesigner.ToPropertyName].Value; if (!modelItemToGuid.ContainsKey(destinationState)) { modelItemToGuid.Add(destinationState, Guid.NewGuid().ToString()); } CopiedTransitionDestinationState = destinationState; return(modelItemToGuid[destinationState]); } } itemsToCopy.RemoveAll(item => item.ItemType == typeof(Transition)); // Save the locations of copied items relative to the statemachine editor to the metadata. // The metadata will be used to translate the location view states of pasted items to the pasting target. PointCollection metaData = new PointCollection(); foreach (ModelItem modelItem in itemsToCopy) { object viewState = this.ViewStateService.RetrieveViewState(modelItem, ShapeLocationViewStateKey); Point location = (Point)viewState; StateContainerEditor parentDesigner = VisualTreeUtils.FindVisualAncestor <StateContainerEditor>(GetStateView(modelItem)); location = parentDesigner.panel.GetLocationRelativeToOutmostPanel(location); metaData.Add(location); } CopiedTransitionDestinationState = null; return(metaData); }
// a version of IsAncestorOf that stops looking when it finds an ancestor // of the given type internal static bool IsAncestorOf(DependencyObject ancestor, DependencyObject descendant, Type stopType) { if (ancestor == null) { throw new ArgumentNullException("ancestor"); } if (descendant == null) { throw new ArgumentNullException("descendant"); } VisualTreeUtils.EnsureVisual(ancestor); VisualTreeUtils.EnsureVisual(descendant); // Walk up the parent chain of the descendant until we run out of parents, // or we find the ancestor, or we reach a node of the given type. DependencyObject current = descendant; while ((current != null) && (current != ancestor) && !stopType.IsInstanceOfType(current)) { Visual visual; Visual3D visual3D; if ((visual = current as Visual) != null) { current = visual.InternalVisualParent; } else if ((visual3D = current as Visual3D) != null) { current = visual3D.InternalVisualParent; } else { current = null; } } return(current == ancestor); }
private void OnContentRenderedAction(object sender, EventArgs args) { //manually fill drop down menu foreach (var item in LocalizedTexts) { //get Combobox of current translation var uiElement = (UIElement)TranslationItems.ItemContainerGenerator.ContainerFromItem(item); var comboBox = VisualTreeUtils.GetVisualChildCollection <ComboBox>(uiElement).First(); comboBox.Items.Clear(); //fill known translations var textLocalization = (TextLocalization)comboBox.DataContext; var knownTranslations = textLocalization.KnownTranslations; if (knownTranslations != null) { foreach (var knownTranslation in knownTranslations) { comboBox.Items.Add(new ComboBoxItem { Background = Brushes.DeepSkyBlue, Content = knownTranslation }); } } //if no known translations found, add No suggestions messge if (comboBox.Items.Count <= 0) { var dummyComboBoxItem = new ComboBoxItem { FontStyle = FontStyles.Italic, Content = "No suggestions", IsHitTestVisible = false }; comboBox.Items.Add(dummyComboBoxItem); } } }
public void VerifyVSMStatesForPhotosAndInitials() { RunOnUIThread.Execute(() => { var personPicture = new PersonPicture(); Content = personPicture; Content.UpdateLayout(); var initialsTextBlock = (TextBlock)VisualTreeUtils.FindVisualChildByName(personPicture, "InitialsTextBlock"); personPicture.IsGroup = true; Content.UpdateLayout(); Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe MDL2 Assets"); Verify.AreEqual(initialsTextBlock.Text, "\xE716"); personPicture.IsGroup = false; personPicture.Initials = "JS"; Content.UpdateLayout(); Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe UI"); Verify.AreEqual(initialsTextBlock.Text, "JS"); personPicture.Initials = ""; Content.UpdateLayout(); Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe MDL2 Assets"); Verify.AreEqual(initialsTextBlock.Text, "\xE77B"); // Make sure that custom FontFamily takes effect after the control is created // and also goes back to the MDL2 font after setting IsGroup = true. personPicture.FontFamily = new FontFamily("Segoe UI Emoji"); personPicture.Initials = "👍"; Content.UpdateLayout(); Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe UI Emoji"); Verify.AreEqual(initialsTextBlock.Text, "👍"); personPicture.IsGroup = true; Content.UpdateLayout(); Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe MDL2 Assets"); Verify.AreEqual(initialsTextBlock.Text, "\xE716"); }); }
public void TreeViewBackgroundTest() { RunOnUIThread.Execute(() => { var treeView = new TreeView(); Content = treeView; Content.UpdateLayout(); var treeViewList = VisualTreeUtils.FindVisualChildByName(treeView, "ListControl") as TreeViewList; // Make sure the TreeViewList does not already have the background color we are using for this test. bool testCondition = treeViewList.Background is SolidColorBrush brush && brush.Color == Colors.Green; Verify.IsFalse(testCondition, "The default TreeView background color should not match the test color used."); // Check if the Background API affects the TreeView control. treeView.Background = new SolidColorBrush(Colors.Green); Content.UpdateLayout(); testCondition = treeViewList.Background is SolidColorBrush brush2 && brush2.Color == Colors.Green; Verify.IsTrue(testCondition, "The TreeView background UI should have matched the specified test color."); }); }
private bool IsMouseOnDragHandle(MouseButtonEventArgs e) { HitTestResult result = VisualTreeHelper.HitTest(this.Designer.scrollableContent, e.GetPosition(this.Designer.scrollableContent)); if (result != null) { WorkflowViewElement view = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(result.VisualHit); if (view != null && view.DragHandle != null) { GeneralTransform transform = view.DragHandle.TransformToAncestor(this.Designer); Fx.Assert(transform != null, "transform should not be null"); Point topLeft = transform.Transform(new Point(0, 0)); Point bottomRight = transform.Transform(new Point(view.DragHandle.ActualWidth, view.DragHandle.ActualHeight)); Rect dragHandleRect = new Rect(topLeft, bottomRight); if (dragHandleRect.Contains(e.GetPosition(this.Designer))) { return(true); } } } return(false); }
// Gets the children of the contained CategoryContainer, returning AutomationPeers // for CategoryEditors followed by AutomationPeers for any left-over properties private List <AutomationPeer> GetChildrenCore() { List <AutomationPeer> children = new List <AutomationPeer>(); if (_container != null) { AddCategoryEditors(children, VisualTreeUtils.GetNamedChild <ItemsControl>(_container, "PART_BasicCategoryEditors"), Resources.PropertyEditing_BasicCategoryEditors); AddCategoryProperties(children, VisualTreeUtils.GetNamedChild <ItemsControl>(_container, "PART_BasicPropertyList")); if (_container.Expanded) { Expander advancedExpander = VisualTreeUtils.GetNamedChild <Expander>(_container, "PART_AdvancedExpander"); if (advancedExpander != null && advancedExpander.Visibility == Visibility.Visible) { children.Add(new AdvancedCategoryContainerAutomationPeer(_container, advancedExpander)); } } } return(children); }
// This takes a FrameworkElement parameter so you can pass in either a ColorPicker or a ColorSpectrum. private void SetAsRootAndWaitForColorSpectrumFill(FrameworkElement element) { ManualResetEvent spectrumLoadedEvent = new ManualResetEvent(false); RunOnUIThread.Execute(() => { element.Loaded += (sender, args) => { var spectrumRectangle = VisualTreeUtils.FindVisualChildByName(element, "SpectrumRectangle") as Rectangle; Verify.IsNotNull(spectrumRectangle); spectrumRectangle.RegisterPropertyChangedCallback(Shape.FillProperty, (o, dp) => { spectrumLoadedEvent.Set(); }); }; Content = element; Content.UpdateLayout(); }); spectrumLoadedEvent.WaitOne(); }
public void Execute(object parameter) { CheckBox senderCheckBox = (CheckBox)parameter; DataGrid dataGrid = VisualTreeUtils.FindParent <DataGrid>(senderCheckBox); IList selectedListViewItemCollection = dataGrid.SelectedItems; if (selectedListViewItemCollection.Count > 1) { // Filter down to just the selected items which aren't aligned with the sender checkbox List <ObservableObject> selectedObservableObjects = selectedListViewItemCollection .Cast <ObservableObject>() .Where(x => x.IsChecked != senderCheckBox.IsChecked) .ToList(); foreach (ObservableObject observableObject in selectedObservableObjects) { bool originalValue = observableObject.IsChecked; observableObject.IsChecked = !(originalValue); } } SelectElementsViewModel.RefreshSelectedElementCount(); }
// Helper method used from GetNeighborSelectionStop() // Returns a parent DependencyObject of the specified element that is // // * Visible AND // * ( Marked with a SelectionStop OR // * Marked with IsSelectionScope = true OR // * Has more than one child ) // private static DependencyObject GetEligibleParent(DependencyObject element, out int childIndex, out int childrenCount, out int childDepth, out bool isSelectionStop, out bool isSelectionScope) { childDepth = 0; isSelectionStop = false; isSelectionScope = false; bool isVisible; do { element = VisualTreeUtils.GetIndexedVisualParent(element, out childrenCount, out childIndex); isSelectionStop = element == null ? false : (GetSelectionStop(element) != null); isSelectionScope = element == null ? false : GetIsSelectionScope(element); isVisible = VisualTreeUtils.IsVisible(element as UIElement); childDepth++; }while ( element != null && (isVisible == false || (isSelectionStop == false && isSelectionScope == false && childrenCount < 2))); return(element); }
public FreeFormPanel GetStateMachineFreeFormPanel() { StateDesigner current = this; WorkflowViewElement parent = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(current); while (parent != null) { if (parent is StateDesigner) { current = (StateDesigner)parent; parent = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(current); } else if (parent is StateMachineDesigner) { return(VisualTreeUtils.FindVisualAncestor <FreeFormPanel>(current)); } else { return(null); } } return(null); }
// This takes a FrameworkElement parameter so you can pass in either a ColorPicker or a ColorSpectrum. private void SetAsRootAndWaitForColorSpectrumFill(FrameworkElement element) { ManualResetEvent spectrumLoadedEvent = new ManualResetEvent(false); RunOnUIThread.Execute(() => { element.Loaded += (sender, args) => { var spectrumRectangle = VisualTreeUtils.FindVisualChildByName(element, "SpectrumRectangle") as Rectangle; Verify.IsNotNull(spectrumRectangle); spectrumRectangle.RegisterPropertyChangedCallback(Shape.FillProperty, (o, dp) => { spectrumLoadedEvent.Set(); }); }; StackPanel root = new StackPanel(); root.Children.Add(element); MUXControlsTestApp.App.TestContentRoot = root; }); spectrumLoadedEvent.WaitOne(); }
public void VerifyClearingAlphaChannelInputFieldDoesNotCrash() { ColorPicker colorPicker = null; RunOnUIThread.Execute(() => { colorPicker = new ColorPicker(); colorPicker.IsAlphaEnabled = true; Content = colorPicker; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { var alphaChannelTextBox = VisualTreeUtils.FindVisualChildByName(colorPicker, "AlphaTextBox") as TextBox; Verify.IsGreaterThan(alphaChannelTextBox.Text.Length, 0, "Alpha channel TextBox should have not been empty."); // Clearing the alpha channel input field should not crash the app. alphaChannelTextBox.Text = ""; }); }
public void TabViewScrollToTheMiddleButton_Click(object sender, RoutedEventArgs e) { var scrollViewer = VisualTreeUtils.FindVisualChildByName(Tabs, "ScrollViewer") as ScrollViewer; scrollViewer.ChangeView(scrollViewer.ScrollableWidth / 2.0f, null, null, true); }
// ISelectionPathInterpreter Members public DependencyObject ResolveSelectionPath(CategoryList root, SelectionPath path, out bool pendingGeneration) { pendingGeneration = false; if (path == null || !string.Equals(PathTypeId, path.PathTypeId)) { Debug.Fail("Invalid SelectionPath specified."); return(null); } if (root == null) { Debug.Fail("No CategoryList specified."); return(null); } string[] pathValues = path.Path.Split(','); if (pathValues.Length < 1) { Debug.Fail("Invalid SelectionPath specified."); return(null); } // // Note: By the time this method gets called, all the visuals should have been expanded // and rendered. Hence, if we can't find a visual in the visual tree, it doesn't exist // and we shouldn't worry about trying to expand some parent visual and waiting for it // to render. // ModelCategoryEntry parentCategory; PropertyEntry currentProperty = root.FindPropertyEntry(PersistedStateUtilities.Unescape(pathValues[0]), out parentCategory); PropertyContainer currentContainer = root.FindPropertyEntryVisual(currentProperty, parentCategory, out pendingGeneration); DependencyObject lastFoundContainer = currentContainer; int pathIndex = 1; while (currentContainer != null && pathIndex < pathValues.Length) { SubPropertyEditor subPropertyEditor = VisualTreeUtils.GetTemplateChild <SubPropertyEditor>(currentContainer); if (subPropertyEditor == null) { break; } // If the subpropertyEditor is not expanded and is expandable, we won't be able to get the target property's visual // element, Expand it, set pendingGeneration to True, and return null. Expect the caller to call again. if (subPropertyEditor.IsExpandable && !subPropertyEditor.IsExpanded) { subPropertyEditor.IsExpanded = true; pendingGeneration = true; return(null); } PropertyEntry property = subPropertyEditor.FindSubPropertyEntry(PersistedStateUtilities.Unescape(pathValues[pathIndex])); if (property == null) { break; } currentContainer = subPropertyEditor.FindSubPropertyEntryVisual(property); lastFoundContainer = currentContainer ?? lastFoundContainer; pathIndex++; } if (lastFoundContainer == null) { return(null); } return(lastFoundContainer); }
// Helper method that return true if the given element is marked with a SelectionStop, // if it derives from the specified Type, and if it is Visible (assuming it derives from UIElement) // private static bool IsEligibleSelectionStop <T>(DependencyObject element) where T : DependencyObject { return((GetSelectionStop(element) != null) && typeof(T).IsAssignableFrom(element.GetType()) && VisualTreeUtils.IsVisible(element as UIElement)); }
internal static ConnectionPoint ConnectionPointHitTest(Point hitPoint, ConnectionPointsAdorner adorner) { FreeFormPanel panel = VisualTreeUtils.FindVisualAncestor <FreeFormPanel>(adorner.AdornedElement); return(ConnectionPointHitTest(hitPoint, adorner.ConnectionPoints, panel)); }
public void VerifyVSMStatesForPhotosAndInitials() { PersonPicture personPicture = null; TextBlock initialsTextBlock = null; RunOnUIThread.Execute(() => { personPicture = new PersonPicture(); MUXControlsTestApp.App.TestContentRoot = personPicture; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { initialsTextBlock = (TextBlock)VisualTreeUtils.FindVisualChildByName(personPicture, "InitialsTextBlock"); personPicture.IsGroup = true; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe MDL2 Assets"); Verify.AreEqual(initialsTextBlock.Text, "\xE716"); personPicture.IsGroup = false; personPicture.Initials = "JS"; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe UI"); Verify.AreEqual(initialsTextBlock.Text, "JS"); personPicture.Initials = ""; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe MDL2 Assets"); Verify.AreEqual(initialsTextBlock.Text, "\xE77B"); // Make sure that custom FontFamily takes effect after the control is created // and also goes back to the MDL2 font after setting IsGroup = true. personPicture.FontFamily = new FontFamily("Segoe UI Emoji"); personPicture.Initials = "👍"; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe UI Emoji"); Verify.AreEqual(initialsTextBlock.Text, "👍"); personPicture.IsGroup = true; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe MDL2 Assets"); Verify.AreEqual(initialsTextBlock.Text, "\xE716"); }); }
public void VerifyExpandCollapseChevronVisibility() { NavigationView navView = null; NavigationViewItem parentItem = null; ObservableCollection <string> children = null; RunOnUIThread.Execute(() => { navView = new NavigationView(); Content = navView; children = new ObservableCollection <string>(); parentItem = new NavigationViewItem() { Content = "ParentItem", MenuItemsSource = children }; navView.MenuItems.Add(parentItem); navView.Width = 1008; // forces the control into Expanded mode so that the menu renders Content.UpdateLayout(true); UIElement chevronUIElement = (UIElement)VisualTreeUtils.FindVisualChildByName(parentItem, "ExpandCollapseChevron"); Verify.IsTrue(chevronUIElement.Visibility == Visibility.Collapsed, "chevron should have been collapsed as NavViewItem has no children"); // Add a child to parentItem through the MenuItemsSource API. This should make the chevron visible. children.Add("Child 1"); Content.UpdateLayout(true); Verify.IsTrue(chevronUIElement.Visibility == Visibility.Visible, "chevron should have been visible as NavViewItem now has children"); // Remove all children of parentItem. This should collapse the chevron children.Clear(); Content.UpdateLayout(true); Verify.IsTrue(chevronUIElement.Visibility == Visibility.Collapsed, "chevron should have been collapsed as NavViewItem no longer has children"); // Add a child to parentItem and set the MenuItemsSource as null. This should collapse the chevron children.Add("Child 2"); Content.UpdateLayout(true); // we are doing this so that when we set MenuItemsSource as null, we can check if the chevron's visibility really changes Verify.IsTrue(chevronUIElement.Visibility == Visibility.Visible, "chevron should have been visible as NavViewItem now has children"); parentItem.MenuItemsSource = null; Content.UpdateLayout(true); Verify.IsTrue(chevronUIElement.Visibility == Visibility.Collapsed, "chevron should have been collapsed as NavViewItem no longer has children"); // Add a child to parentItem through the MenuItems API. This should make the chevron visible. parentItem.MenuItems.Add(new NavigationViewItem() { Content = "Child 3" }); Content.UpdateLayout(true); Verify.IsTrue(chevronUIElement.Visibility == Visibility.Visible, "chevron should have been visible as NavViewItem now has children"); // Remove all children of parentItem. This should collapse the chevron parentItem.MenuItems.Clear(); Content.UpdateLayout(true); Verify.IsTrue(chevronUIElement.Visibility == Visibility.Collapsed, "chevron should have been collapsed as NavViewItem no longer has children"); }); }
public async Task VerifyVSMStatesForPhotosAndInitials() { PersonPicture personPicture = null; TextBlock initialsTextBlock = null; #if WINDOWS_UWP string symbolsFontName = "Segoe MDL2 Assets"; #elif __ANDROID__ || __SKIA__ string symbolsFontName = "ms-appx:///Assets/Fonts/uno-fluentui-assets.ttf#Symbols"; #else string symbolsFontName = "Symbols"; #endif await RunOnUIThread.ExecuteAsync(() => { personPicture = new PersonPicture(); global::Private.Infrastructure.TestServices.WindowHelper.WindowContent = personPicture; }); await global::Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.ExecuteAsync(() => { initialsTextBlock = (TextBlock)VisualTreeUtils.FindVisualChildByName(personPicture, "InitialsTextBlock"); personPicture.IsGroup = true; }); await global::Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.ExecuteAsync(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, symbolsFontName); Verify.AreEqual(initialsTextBlock.Text, "\xE716"); personPicture.IsGroup = false; personPicture.Initials = "JS"; }); await global::Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.ExecuteAsync(() => { #if false Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe UI"); #endif Verify.AreEqual(initialsTextBlock.Text, "JS"); personPicture.Initials = ""; }); await global::Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.ExecuteAsync(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, symbolsFontName); Verify.AreEqual(initialsTextBlock.Text, "\xE77B"); // Make sure that custom FontFamily takes effect after the control is created // and also goes back to the MDL2 font after setting IsGroup = true. personPicture.FontFamily = new FontFamily("Segoe UI Emoji"); personPicture.Initials = "👍"; }); await global::Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.ExecuteAsync(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe UI Emoji"); Verify.AreEqual(initialsTextBlock.Text, "👍"); personPicture.IsGroup = true; }); await global::Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.ExecuteAsync(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, symbolsFontName); Verify.AreEqual(initialsTextBlock.Text, "\xE716"); }); }
public void OnItemsPasted(List <object> itemsToPaste, List <object> metaData, Point pastePoint, WorkflowViewElement pastePointReference) { if (this.ModelItem.ItemType == typeof(State)) { WorkflowViewElement view = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(this); if (view != null) { StateContainerEditor container = (StateContainerEditor)DragDropHelper.GetCompositeView(view); container.OnItemsPasted(itemsToPaste, metaData, pastePoint, pastePointReference); } return; } if (itemsToPaste.Count == 1 && itemsToPaste.First() is Transition) { if (metaData == null || metaData.Count != 1 || !(metaData.First() is string)) { ShowMessageBox(SR.PasteTransitionWithoutDestinationState); return; } ModelItem destinationState = FindState(metaData.First() as string); if (destinationState == null) { ShowMessageBox(SR.PasteTransitionWithoutDestinationState); return; } this.PopulateVirtualizingContainer(destinationState); ModelItem[] selectedItems = this.Context.Items.GetValue <Selection>().SelectedObjects.ToArray(); string errorMessage; if (!CanPasteTransition(destinationState, out errorMessage, selectedItems)) { ShowMessageBox(errorMessage); return; } Transition pastedTransition = itemsToPaste.First() as Transition; Fx.Assert(pastedTransition != null, "Copied Transition should not be null."); using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(System.Activities.Presentation.SR.PropertyChangeEditingScopeDescription)) { string displayName = pastedTransition.DisplayName; bool isFirst = true; foreach (ModelItem selectedItem in selectedItems) { if (!isFirst) { StringReader reader = new StringReader(XamlServices.Save(pastedTransition)); pastedTransition = (Transition)XamlServices.Load(reader); } ModelItem transitionModelItem = this.Context.Services.GetRequiredService <ModelTreeManager>().WrapAsModelItem(pastedTransition); ModelItem sourceState = selectedItem; sourceState.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(transitionModelItem); transitionModelItem.Properties[TransitionDesigner.ToPropertyName].SetValue(destinationState); if (isFirst) { this.ViewStateService.RemoveViewState(transitionModelItem, ConnectorLocationViewStateKey); this.ViewStateService.RemoveViewState(transitionModelItem, SrcConnectionPointIndexStateKey); this.ViewStateService.RemoveViewState(transitionModelItem, DestConnectionPointIndexStateKey); isFirst = false; } } es.Complete(); } } else { List <ModelItem> modelItemsPasted = new List <ModelItem>(); List <State> states = new List <State>(); foreach (object obj in itemsToPaste) { State state; if (obj is FinalState) { state = new State() { DisplayName = DefaultFinalStateDisplayName, IsFinal = true }; } else { state = (State)obj; if (state.DisplayName == null) { state.DisplayName = DefaultStateDisplayName; } } states.Add(state); } RemoveDanglingTransitions(states); using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit( System.Activities.Presentation.SR.CollectionAddEditingScopeDescription)) { // Fix 157591 by storing the height and width of the container "before" the new states are added to the // panel, and group the insertion inside one editing scope - such that Undo will also restore the // size of the StateMachineContainer to pre-insert size. StoreShapeSizeWithUndoRecursively(this.ModelItem); foreach (State state in states) { ModelItem stateModelItem = (this.ModelItem.ItemType == typeof(StateMachine)) ? this.ModelItem.Properties[StateMachineDesigner.StatesPropertyName].Collection.Add(state) : GetStateMachineModelItem(this.ModelItem).Properties[StateMachineDesigner.StatesPropertyName].Collection.Add(state); modelItemsPasted.Add(stateModelItem); } es.Complete(); } if (modelItemsPasted.Count > 0) { // translate location view states to be in the coordinate system of the pasting target Fx.Assert(this.ModelItem.ItemType == typeof(StateMachine), "Only StateMachine contain the StateContainerEditor."); this.UpdateLocationViewStatesByMetaData(modelItemsPasted, metaData, this); if (pastePoint.X > 0 && pastePoint.Y > 0) { if (pastePointReference != null) { pastePoint = pastePointReference.TranslatePoint(pastePoint, this.panel); pastePoint.X = pastePoint.X < 0 ? 0 : pastePoint.X; pastePoint.Y = pastePoint.Y < 0 ? 0 : pastePoint.Y; } this.UpdateLocationViewStatesByPoint(modelItemsPasted, pastePoint); } // If paste point is not available, paste the items to the top left corner. else { this.UpdateLocationViewStatesToAvoidOverlap(modelItemsPasted); } } this.Dispatcher.BeginInvoke(() => { if (modelItemsPasted.Count > 0 && modelItemsPasted[0] != null) { Keyboard.Focus(modelItemsPasted[0].View as IInputElement); } this.Context.Items.SetValue(new Selection(modelItemsPasted)); }, DispatcherPriority.ApplicationIdle ); } }
public void IncreaseScrollButton_Click(object sender, RoutedEventArgs e) { var sv = VisualTreeUtils.FindVisualChildByName(Tabs, "ScrollViewer") as ScrollViewer; sv.ChangeView(10000, null, null, disableAnimation: true); }
private bool IsMouseOverAdorner(MouseButtonEventArgs e) { HitTestResult result = VisualTreeHelper.HitTest(this.Designer.scrollViewer, e.GetPosition(this.Designer.scrollViewer)); return(result != null && VisualTreeUtils.FindVisualAncestor <Adorner>(result.VisualHit) != null); }
public async Task VerifyVSMStatesForPhotosAndInitials() { PersonPicture personPicture = null; TextBlock initialsTextBlock = null; await RunOnUIThread.Execute(() => { personPicture = new PersonPicture(); Private.Infrastructure.TestServices.WindowHelper.WindowContent = personPicture; }); await Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.Execute(() => { initialsTextBlock = (TextBlock)VisualTreeUtils.FindVisualChildByName(personPicture, "InitialsTextBlock"); personPicture.IsGroup = true; }); await Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.Execute(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe MDL2 Assets"); Verify.AreEqual(initialsTextBlock.Text, "\xE716"); personPicture.IsGroup = false; personPicture.Initials = "JS"; }); await Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.Execute(() => { #if false Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe UI"); #endif Verify.AreEqual(initialsTextBlock.Text, "JS"); personPicture.Initials = ""; }); await Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.Execute(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe MDL2 Assets"); Verify.AreEqual(initialsTextBlock.Text, "\xE77B"); // Make sure that custom FontFamily takes effect after the control is created // and also goes back to the MDL2 font after setting IsGroup = true. personPicture.FontFamily = new FontFamily("Segoe UI Emoji"); personPicture.Initials = "👍"; }); await Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.Execute(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe UI Emoji"); Verify.AreEqual(initialsTextBlock.Text, "👍"); personPicture.IsGroup = true; }); await Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); await RunOnUIThread.Execute(() => { Verify.AreEqual(initialsTextBlock.FontFamily.Source, "Segoe MDL2 Assets"); Verify.AreEqual(initialsTextBlock.Text, "\xE716"); }); }
public void TabViewScrollToTheRightButton_Click(object sender, RoutedEventArgs e) { var scrollViewer = VisualTreeUtils.FindVisualChildByName(Tabs, "ScrollViewer") as ScrollViewer; scrollViewer.ChangeView(double.MaxValue, null, null, true); }
protected override void OnPreviewMouseUp(MouseButtonEventArgs e) { base.OnPreviewMouseUp(e); if (_canvasDragStartPoint != null) { ReleaseMouseCapture(); _canvasDragStartPoint = null; } var hitTestResult = VisualTreeHelper.HitTest(this, e.GetPosition(this)); var originalSource = hitTestResult.VisualHit; if (_endLinkPoint != null) { ReleaseMouseCapture(); PinViewModel pinViewModel = null; var bullet = VisualTreeUtils.FindParent <Bullet>(originalSource); if (bullet != null) { pinViewModel = VisualTreeUtils.FindDataContext <PinViewModel>(bullet); } OnPreviewPinMouseUp(pinViewModel, e); _endLinkPoint = null; } if (_nodeDraged != null) { ReleaseMouseCapture(); _nodeDraged = null; } // if (_currentRope != null) // { // var hitTestResult = VisualTreeHelper.HitTest(this, e.GetPosition(this)); // var pin = VisualTreeUtils.FindParent<Pin>(hitTestResult.VisualHit); // var ropeAdded = false; // if (pin != null) // { // if (_currentRope.EndPoint == _currentRopeFreePoint) // { // if (pin.IsInputPin) // { // if (InnerControls.OfType<Rope>().All(rope => rope.EndPoint != _pinLocations[pin])) // { // _currentRope.EndPoint = _pinLocations[pin]; // Node.Link(_sourcePin.Node, _sourcePin.NodePin, pin.Node, pin.NodePin); // pin.Node.Pulse(); // ropeAdded = true; // } // } // } // else // { // if (!pin.IsInputPin) // { // _currentRope.BeginPoint = _pinLocations[pin]; // Node.Link(pin.Node, pin.NodePin, _targetPin.Node, _targetPin.NodePin); // pin.Node.Pulse(); // ropeAdded = true; // } // } // } // // if (!ropeAdded) // { // InnerControls.Remove(_currentRope); // } // // _currentRope = null; // _currentRopeFreePoint = null; // } }
[TestProperty("TestPass:IncludeOnlyOn", "Desktop")] // TeachingTip doesn't appear to show up correctly in OneCore. public void TeachingTipBackgroundTest() { TeachingTip teachingTip = null, teachingTipLightDismiss = null; SolidColorBrush blueBrush = null; Brush lightDismissBackgroundBrush = null; var loadedEvent = new AutoResetEvent(false); RunOnUIThread.Execute(() => { Grid root = new Grid(); teachingTip = new TeachingTip(); teachingTip.Loaded += (object sender, RoutedEventArgs args) => { loadedEvent.Set(); }; teachingTipLightDismiss = new TeachingTip(); teachingTipLightDismiss.IsLightDismissEnabled = true; // Set LightDismiss background before show... it shouldn't take effect in the tree blueBrush = new SolidColorBrush(Colors.Blue); teachingTipLightDismiss.Background = blueBrush; root.Resources.Add("TeachingTip", teachingTip); root.Resources.Add("TeachingTipLightDismiss", teachingTipLightDismiss); lightDismissBackgroundBrush = MUXControlsTestApp.App.Current.Resources["TeachingTipTransientBackground"] as Brush; Verify.IsNotNull(lightDismissBackgroundBrush, "lightDismissBackgroundBrush"); teachingTip.IsOpen = true; teachingTipLightDismiss.IsOpen = true; MUXControlsTestApp.App.TestContentRoot = root; }); IdleSynchronizer.Wait(); loadedEvent.WaitOne(); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { var redBrush = new SolidColorBrush(Colors.Red); teachingTip.SetValue(TeachingTip.BackgroundProperty, redBrush); Verify.AreSame(redBrush, teachingTip.GetValue(TeachingTip.BackgroundProperty) as Brush); Verify.AreSame(redBrush, teachingTip.Background); teachingTip.Background = blueBrush; Verify.AreSame(blueBrush, teachingTip.Background); { var popup = TeachingTipTestHooks.GetPopup(teachingTip); var child = popup.Child; var grandChild = VisualTreeHelper.GetChild(child, 0); Verify.AreSame(blueBrush, ((Grid)grandChild).Background, "Checking TeachingTip.Background TemplateBinding works"); } { var popup = TeachingTipTestHooks.GetPopup(teachingTipLightDismiss); var child = popup.Child as Grid; Log.Comment("Checking LightDismiss TeachingTip Background is using resource for first invocation"); Grid tailEdgeBorder = VisualTreeUtils.FindVisualChildByName(child, "TailEdgeBorder") as Grid; Polygon tailPolygon = VisualTreeUtils.FindVisualChildByName(child, "TailPolygon") as Polygon; Polygon topTailPolygonHighlight = VisualTreeUtils.FindVisualChildByName(child, "TopTailPolygonHighlight") as Polygon; Grid contentRootGrid = VisualTreeUtils.FindVisualChildByName(child, "ContentRootGrid") as Grid; ContentPresenter mainContentPresenter = VisualTreeUtils.FindVisualChildByName(child, "MainContentPresenter") as ContentPresenter; Border heroContentBorder = VisualTreeUtils.FindVisualChildByName(child, "HeroContentBorder") as Border; VerifyLightDismissTipBackground(tailEdgeBorder.Background, "TailEdgeBorder"); VerifyLightDismissTipBackground(tailPolygon.Fill, "TailPolygon"); VerifyLightDismissTipBackground(topTailPolygonHighlight.Fill, "TopTailPolygonHighlight"); VerifyLightDismissTipBackground(contentRootGrid.Background, "ContentRootGrid"); VerifyLightDismissTipBackground(mainContentPresenter.Background, "MainContentPresenter"); VerifyLightDismissTipBackground(heroContentBorder.Background, "HeroContentBorder"); void VerifyLightDismissTipBackground(Brush brush, string uiPart) { if (lightDismissBackgroundBrush != brush) { if (brush is SolidColorBrush actualSolidBrush) { string teachingTipMessage = $"LightDismiss TeachingTip's {uiPart} Background is SolidColorBrush with color {actualSolidBrush.Color}"; Log.Comment(teachingTipMessage); Verify.Fail(teachingTipMessage); } else { Verify.AreSame(lightDismissBackgroundBrush, brush, $"Checking LightDismiss TeachingTip's {uiPart} Background is using resource for first invocation"); } } } } teachingTip.IsLightDismissEnabled = true; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Verify.AreEqual(blueBrush.Color, ((SolidColorBrush)teachingTip.Background).Color); var popup = TeachingTipTestHooks.GetPopup(teachingTip); var child = popup.Child as Grid; Grid tailEdgeBorder = VisualTreeUtils.FindVisualChildByName(child, "TailEdgeBorder") as Grid; Polygon tailPolygon = VisualTreeUtils.FindVisualChildByName(child, "TailPolygon") as Polygon; Polygon topTailPolygonHighlight = VisualTreeUtils.FindVisualChildByName(child, "TopTailPolygonHighlight") as Polygon; Grid contentRootGrid = VisualTreeUtils.FindVisualChildByName(child, "ContentRootGrid") as Grid; ContentPresenter mainContentPresenter = VisualTreeUtils.FindVisualChildByName(child, "MainContentPresenter") as ContentPresenter; Border heroContentBorder = VisualTreeUtils.FindVisualChildByName(child, "HeroContentBorder") as Border; VerifyBackgroundChanged(tailEdgeBorder.Background, "TailEdgeBorder"); VerifyBackgroundChanged(tailPolygon.Fill, "TailPolygon"); VerifyBackgroundChanged(topTailPolygonHighlight.Fill, "TopTailPolygonHighlight"); VerifyBackgroundChanged(contentRootGrid.Background, "ContentRootGrid"); VerifyBackgroundChanged(mainContentPresenter.Background, "MainContentPresenter"); VerifyBackgroundChanged(heroContentBorder.Background, "HeroContentBorder"); void VerifyBackgroundChanged(Brush brush, string uiPart) { // If we can no longer cast the background brush to a solid color brush then changing the // IsLightDismissEnabled has changed the background as we expected it to. if (brush is SolidColorBrush solidColorBrush) { Verify.AreNotEqual(blueBrush.Color, solidColorBrush.Color, $"TeachingTip's {uiPart} Background should have changed"); } } }); }
public void GetScrollIncreaseButtonEnabled_Click(object sender, RoutedEventArgs e) { var scrollIncreaseButton = VisualTreeUtils.FindVisualChildByName(Tabs, "ScrollIncreaseButton") as RepeatButton; ScrollIncreaseButtonEnabled.Text = scrollIncreaseButton.IsEnabled ? "True" : "False"; }
public void TreeViewClearAndSetAtTest() { RunOnUIThread.Execute(() => { var treeView = new TreeView(); Content = treeView; Content.UpdateLayout(); var listControl = VisualTreeUtils.FindVisualChildByName(treeView, "ListControl") as TreeViewList; // Verify TreeViewNode::SetAt TreeViewNode setAtChildCheckNode = new TreeViewNode() { Content = "Set At Child" }; TreeViewNode setAtRootCheckNode = new TreeViewNode() { Content = "Set At Root" }; TreeViewNode child1 = new TreeViewNode() { Content = "Child 1" }; child1.Children.Add(new TreeViewNode() { Content = "Child 1:1" }); TreeViewNode child2 = new TreeViewNode() { Content = "Child 2" }; child2.Children.Add(new TreeViewNode() { Content = "Child 2:1" }); child2.Children.Add(new TreeViewNode() { Content = "Child 2:2" }); treeView.RootNodes.Add(child1); child1.IsExpanded = true; treeView.RootNodes.Add(child2); Verify.AreEqual(listControl.Items.Count, 3); // SetAt node under child node which is not expanded child2.Children[1] = setAtChildCheckNode; Verify.AreEqual(listControl.Items.Count, 3); // SetAt node under root node and child2 is expanded treeView.RootNodes[0] = setAtRootCheckNode; child2.IsExpanded = true; Verify.AreEqual(listControl.Items.Count, 4); // Verify RootNode.Clear treeView.RootNodes.Clear(); Verify.AreEqual(listControl.Items.Count, 0); // test clear without any child node treeView.RootNodes.Clear(); Verify.AreEqual(listControl.Items.Count, 0); }); }