private void AddChildren(GeneratorPosition pos, int itemCount) { Debug.Assert(_itemContainerGenerator != null, "Encountered a null _itemContainerGenerator while receiving an Add action from a generator."); IItemContainerGenerator generator = (IItemContainerGenerator)_itemContainerGenerator; using (generator.StartAt(pos, GeneratorDirection.Forward, true)) { for (int i = 0; i < itemCount; i++) { bool isNewlyRealized; UIElement e = generator.GenerateNext(out isNewlyRealized) as UIElement; if (e != null) { _uiElementCollection.Insert(pos.Index + 1 + i, e); generator.PrepareItemContainer(e); } // check this //else //{ // _itemContainerGenerator.Verify(); //} } } }
/// <summary> /// Agrega componentes a la ventana en caso de que /// se marque la casilla de seguro /// </summary> private void AgregarComponentes_Seguro() { lb_numPolizaSeguro.Content = "Número de poliza de seguro"; lb_nombreAseguradora.Content = "Nombre de aseguradora"; tb_nombreAseguradora.Height = 23; tb_numPolizaSeguro.Height = 23; UIElementCollection componentes = sp_componentes.Children; componentes.Insert(componentes.IndexOf(lb_color), tb_numPolizaSeguro); componentes.Insert(componentes.IndexOf(tb_numPolizaSeguro), lb_numPolizaSeguro); componentes.Insert(componentes.IndexOf(lb_numPolizaSeguro), tb_nombreAseguradora); componentes.Insert(componentes.IndexOf(tb_nombreAseguradora), lb_nombreAseguradora); }
public void ArgumentChecks() { Canvas canvas = new Canvas(); UIElementCollection c = canvas.Children; Assert.Throws <ArgumentNullException> (() => c.Add(null), "Add"); Assert.Throws <ArgumentNullException> (() => c.Insert(0, null), "Insert null"); Assert.Throws <ArgumentOutOfRangeException> (() => c.Insert(-1, new Rectangle()), "Insert negative"); Assert.Throws <ArgumentOutOfRangeException> (() => c.RemoveAt(-1), "RemoveAt negative"); Assert.Throws <ArgumentOutOfRangeException> (() => Console.WriteLine(c [-1] == null), "this getter"); Assert.Throws <ArgumentOutOfRangeException> (() => c [-1] = new Rectangle(), "this setter"); Assert.IsFalse(c.Contains(null), "Contains"); Assert.IsFalse(c.Remove(null), "Remove"); Assert.AreEqual(-1, c.IndexOf(null), "IndexOf"); }
public static void Switch(this UIElementCollection col, int from, int to) { var smallestIndex = from; var biggestIndex = to; if (from > to) { smallestIndex = to; biggestIndex = from; } var ObjA = col[smallestIndex]; var ObjB = col[biggestIndex]; col.RemoveAt(biggestIndex); col.RemoveAt(smallestIndex); col.Insert(smallestIndex, ObjB); col.Insert(biggestIndex, ObjA); }
private void Shuffle(UIElementCollection list) { Random rand = new Random(); int n = list.Count; while (n > 1) { n--; int k = rand.Next(n + 1); Button value = list.OfType <Button>().ElementAt(n); list.Remove(value); list.Insert(k, value); } }
void AddAdornerToChildren(AdornerPanel adornerPanel) { UIElementCollection children = this.Children; int i = 0; for (i = 0; i < children.Count; i++) { AdornerPanel p = (AdornerPanel)children[i]; if (p.Order > adornerPanel.Order) { break; } } children.Insert(i, adornerPanel); }
public GenericWindow(string windowTitle, string[] buttons) { Window mainWindow = Application.Current.MainWindow; this.Left = mainWindow.Left + (mainWindow.Width - this.Width) / 2; this.Top = mainWindow.Top + (mainWindow.Height - this.Height) / 2; this.Owner = mainWindow; InitializeComponent(); UIElementCollection area = this.buttonArea.Children; foreach (string buttonText in buttons) { Button button = new Button() { Content = buttonText, Name = buttonText.Replace(" ", "") }; //Name does not accept spaces button.Click += GetButtonNumber; area.Insert(area.Count - 1, button); if (buttonText != buttons[buttons.Length - 1]) { area.Insert(area.Count - 1, new Label()); } } }
/// <summary> /// Measure the content and store the desired size of the content /// </summary> /// <param name="constraint"></param> /// <returns></returns> protected override Size MeasureOverride(Size constraint) { Size curLineSize = new Size(); _panelSize = new Size(); _wrapWidth = double.IsNaN(WrapWidth) ? constraint.Width : WrapWidth; UIElementCollection children = InternalChildren; int childrenCount = children.Count; // Add ToolBar items which have IsOverflowItem = true ToolBarPanel toolBarPanel = ToolBarPanel; if (toolBarPanel != null) { // Go through the generated items collection and add to the children collection // any that are marked IsOverFlowItem but aren't already in the children collection. // // The order of both collections matters. // // It is assumed that any children that were removed from generated items will have // already been removed from the children collection. List <UIElement> generatedItemsCollection = toolBarPanel.GeneratedItemsCollection; int generatedItemsCount = (generatedItemsCollection != null) ? generatedItemsCollection.Count : 0; int childrenIndex = 0; for (int i = 0; i < generatedItemsCount; i++) { UIElement child = generatedItemsCollection[i]; if ((child != null) && ToolBar.GetIsOverflowItem(child) && !(child is Separator)) { if (childrenIndex < childrenCount) { if (children[childrenIndex] != child) { children.Insert(childrenIndex, child); childrenCount++; } } else { children.Add(child); childrenCount++; } childrenIndex++; } } Debug.Assert(childrenIndex == childrenCount, "ToolBarOverflowPanel.Children count mismatch after transferring children from GeneratedItemsCollection."); } // Measure all children to determine if we need to increase desired wrapWidth for (int i = 0; i < childrenCount; i++) { UIElement child = children[i] as UIElement; child.Measure(constraint); Size childDesiredSize = child.DesiredSize; if (DoubleUtil.GreaterThan(childDesiredSize.Width, _wrapWidth)) { _wrapWidth = childDesiredSize.Width; } } // wrapWidth should not be bigger than constraint.Width _wrapWidth = Math.Min(_wrapWidth, constraint.Width); for (int i = 0; i < children.Count; i++) { UIElement child = children[i] as UIElement; Size sz = child.DesiredSize; if (DoubleUtil.GreaterThan(curLineSize.Width + sz.Width, _wrapWidth)) //need to switch to another line { _panelSize.Width = Math.Max(curLineSize.Width, _panelSize.Width); _panelSize.Height += curLineSize.Height; curLineSize = sz; if (DoubleUtil.GreaterThan(sz.Width, _wrapWidth)) //the element is wider then the constraint - give it a separate line { _panelSize.Width = Math.Max(sz.Width, _panelSize.Width); _panelSize.Height += sz.Height; curLineSize = new Size(); } } else //continue to accumulate a line { curLineSize.Width += sz.Width; curLineSize.Height = Math.Max(sz.Height, curLineSize.Height); } } //the last line size, if any should be added _panelSize.Width = Math.Max(curLineSize.Width, _panelSize.Width); _panelSize.Height += curLineSize.Height; return(_panelSize); }
protected override void DoInsert(NListPatchEntry i) { _target.Insert(i.iInsert, (UIElement)i.Value.Create()); }
/// <summary>Fluent Insert function</summary> public static T Insert2 <T>(this UIElementCollection collection, int index, T item) where T : UIElement { collection.Insert(index, item); return(item); }
/// <summary> /// Insert the visual for the child in the same order as is is defined in the /// VirtualChildren collection so the visuals draw on top of each other in the expected order. /// The trick is that GetNodesIntersecting returns the nodes in pretty much random order depending /// on how the QuadTree decides to break up the canvas. /// /// The thing we should avoid is a linear search through the potentially large collection of /// IVirtualChildren to compute its visible index which is why we have the _visualPositions map. /// We should also avoid a N*M algorithm where N is the number of nodes returned from GetNodesIntersecting /// and M is the number of children already visible. For example, Page down in a zoomed out situation /// gives potentially high N and and M which would basically be an O(n2) algorithm. /// /// So the solution is to use the _visualPositions map to get the expected visual position index /// of a given IVirtualChild, then do a binary search through existing visible children to find the /// insertion point of the new child. So this is O(Log M). /// </summary> /// <param name="child">The IVirtualChild to add visual for</param> public void EnsureVisual(IVirtualChild child) { if (child.Visual != null) { return; } FrameworkElement e = child.CreateVisual(this); e.SetValue(VirtualChildProperty, child); Rect bounds = child.Bounds; Canvas.SetLeft(e, bounds.Left); Canvas.SetTop(e, bounds.Top); // Get the correct absolute position of this child. int position = _visualPositions[child]; // Now do a binary search for the correct insertion position based // on the visual positions of the existing visible children. UIElementCollection c = Children; int min = 0; int max = c.Count - 1; while (max > min + 1) { int i = (min + max) / 2; UIElement v = Children[i]; IVirtualChild n = v.GetValue(VirtualChildProperty) as IVirtualChild; if (n != null) { int index = _visualPositions[n]; if (index > position) { // search from min to i. max = i; } else { // search from i to max. min = i; } } else { // Any nodes without IVirtualChild should be behind the // IVirtualChildren by definition (like the Backdrop). min = i; } } // If 'max' is the last child in the collection, then we need to see // if we have a new last child. if (c.Count > 0 && max == c.Count - 1) { UIElement v = c[max]; IVirtualChild maxchild = v.GetValue(VirtualChildProperty) as IVirtualChild; int maxpos = position; if (maxchild == null || position > _visualPositions[maxchild]) { // Then we have a new last child! max++; } } if (max < 0) { c.Add(e); } else { c.Insert(max, e); } }
/// <summary>Remeasures the <see cref="T:System.Windows.Controls.Primitives.ToolBarOverflowPanel" />. </summary> /// <param name="constraint">Constraint size is an upper limit. The return value should not exceed this size.</param> /// <returns>The desired size.</returns> // Token: 0x060060FB RID: 24827 RVA: 0x001B3298 File Offset: 0x001B1498 protected override Size MeasureOverride(Size constraint) { Size size = default(Size); this._panelSize = default(Size); this._wrapWidth = (double.IsNaN(this.WrapWidth) ? constraint.Width : this.WrapWidth); UIElementCollection internalChildren = base.InternalChildren; int num = internalChildren.Count; ToolBarPanel toolBarPanel = this.ToolBarPanel; if (toolBarPanel != null) { List <UIElement> generatedItemsCollection = toolBarPanel.GeneratedItemsCollection; int num2 = (generatedItemsCollection != null) ? generatedItemsCollection.Count : 0; int num3 = 0; for (int i = 0; i < num2; i++) { UIElement uielement = generatedItemsCollection[i]; if (uielement != null && ToolBar.GetIsOverflowItem(uielement) && !(uielement is Separator)) { if (num3 < num) { if (internalChildren[num3] != uielement) { internalChildren.Insert(num3, uielement); num++; } } else { internalChildren.Add(uielement); num++; } num3++; } } } for (int j = 0; j < num; j++) { UIElement uielement2 = internalChildren[j]; uielement2.Measure(constraint); Size desiredSize = uielement2.DesiredSize; if (DoubleUtil.GreaterThan(desiredSize.Width, this._wrapWidth)) { this._wrapWidth = desiredSize.Width; } } this._wrapWidth = Math.Min(this._wrapWidth, constraint.Width); for (int k = 0; k < internalChildren.Count; k++) { UIElement uielement3 = internalChildren[k]; Size desiredSize2 = uielement3.DesiredSize; if (DoubleUtil.GreaterThan(size.Width + desiredSize2.Width, this._wrapWidth)) { this._panelSize.Width = Math.Max(size.Width, this._panelSize.Width); this._panelSize.Height = this._panelSize.Height + size.Height; size = desiredSize2; if (DoubleUtil.GreaterThan(desiredSize2.Width, this._wrapWidth)) { this._panelSize.Width = Math.Max(desiredSize2.Width, this._panelSize.Width); this._panelSize.Height = this._panelSize.Height + desiredSize2.Height; size = default(Size); } } else { size.Width += desiredSize2.Width; size.Height = Math.Max(desiredSize2.Height, size.Height); } } this._panelSize.Width = Math.Max(size.Width, this._panelSize.Width); this._panelSize.Height = this._panelSize.Height + size.Height; return(this._panelSize); }
public void Insert(int index, ListBoxItem item) { _items.Insert(index, item); item.SetListBox(_listBox); }
public void Add(UIElement element) { _inner.Insert(_offset++, element); }
internal static void Add(string Message, string ButtonText, AcceptEventHandler AcceptHandler) => Stack.Insert(0, new Notification(Message, ButtonText, AcceptHandler, 0));
protected override Size MeasureOverride(Size availableSize) { Panel panel = this.GroupLevelIndicatorPaneHost; if (panel == null) { return(base.MeasureOverride(availableSize)); } DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this); if (dataGridContext != null) { ObservableCollection <GroupDescription> groupDescriptions = DataGridContext.GetGroupDescriptionsHelper(dataGridContext.Items); int leafGroupLevel = GroupLevelIndicatorPane.GetGroupLevel(this); // If Indented is true (default), we use the total groupDescriptions.Count for this DataGridContext int correctedGroupLevel = (this.Indented == true) ? groupDescriptions.Count : leafGroupLevel; // Ensure that the GroupLevel retrieved does not exceeds the number of group descriptions for the DataGridContext correctedGroupLevel = Math.Min(correctedGroupLevel, groupDescriptions.Count); // Then finally, if the GroupLevel is -1, then indent at maximum. if (correctedGroupLevel == -1) { correctedGroupLevel = groupDescriptions.Count; } if ((correctedGroupLevel > 0) && (this.AreGroupsFlattened)) { correctedGroupLevel = (this.Indented) ? 1 : 0; } UIElementCollection children = panel.Children; int childrenCount = children.Count; // If we need to add/remove GroupLevelIndicators from the panel if (correctedGroupLevel != childrenCount) { // When grouping change, we take for granted that the group deepness will change, // so we initialize DataContext of the margin only in there. // Clear all the panel's children! children.Clear(); // Create 1 group margin content presenter for each group level for (int i = correctedGroupLevel - 1; i >= 0; i--) { GroupLevelIndicator groupMargin = new GroupLevelIndicator(); groupMargin.DataContext = dataGridContext.GroupLevelDescriptions[i]; children.Insert(0, new GroupLevelIndicator()); } childrenCount = correctedGroupLevel; this.SetCurrentIndicatorCount(childrenCount); } object item = dataGridContext.GetItemFromContainer(this); for (int i = 0; i < childrenCount; i++) { GroupLevelIndicator groupMargin = children[i] as GroupLevelIndicator; CollectionViewGroup groupForIndicator = GroupLevelIndicatorPane.GetCollectionViewGroupHelper( dataGridContext, groupDescriptions, item, i); GroupConfiguration groupLevelConfig = GroupConfiguration.GetGroupConfiguration( dataGridContext, groupDescriptions, dataGridContext.GroupConfigurationSelector, i, groupForIndicator); if (groupLevelConfig != null) { Binding groupLevelIndicatorStyleBinding = BindingOperations.GetBinding(groupMargin, GroupLevelIndicator.StyleProperty); if ((groupLevelIndicatorStyleBinding == null) || (groupLevelIndicatorStyleBinding.Source != groupLevelConfig)) { groupLevelIndicatorStyleBinding = new Binding("GroupLevelIndicatorStyle"); groupLevelIndicatorStyleBinding.Source = groupLevelConfig; groupMargin.SetBinding(GroupLevelIndicator.StyleProperty, groupLevelIndicatorStyleBinding); } } else { groupMargin.ClearValue(GroupLevelIndicator.StyleProperty); } // If the ShowIndicators property is False or there is already leafGroupLevel GroupLevelIndicators in the panel, // the current newGroupMargin must be hidden. if ((!GroupLevelIndicatorPane.GetShowIndicators(this)) || ((i >= leafGroupLevel) && (leafGroupLevel != -1))) { groupMargin.Visibility = Visibility.Hidden; } else { groupMargin.Visibility = Visibility.Visible; } } } return(base.MeasureOverride(availableSize)); }
/// <inheritdoc /> public void Insert(int index, Inline item) => _collection.Insert(index, item);
SaveToXps ( Size imageSize, String fileName ) { Debug.Assert(!String.IsNullOrEmpty(fileName)); AssertValid(); CheckIfLayingOutGraph("SaveToXps"); // This control will be rehosted by a FixedPage. It can't be a child // of logical trees, so disconnect it from its parent after saving the // current vertex locations. LayoutSaver oLayoutSaver = new LayoutSaver(this.Graph); Debug.Assert(this.Parent is Panel); Panel oParentPanel = (Panel)this.Parent; UIElementCollection oParentChildren = oParentPanel.Children; Int32 iChildIndex = oParentChildren.IndexOf(this); oParentChildren.Remove(this); GraphImageCenterer oGraphImageCenterer = new GraphImageCenterer(this); FixedDocument oFixedDocument = new FixedDocument(); oFixedDocument.DocumentPaginator.PageSize = imageSize; PageContent oPageContent = new PageContent(); FixedPage oFixedPage = new FixedPage(); oFixedPage.Width = imageSize.Width; oFixedPage.Height = imageSize.Height; this.Width = imageSize.Width; this.Height = imageSize.Height; // Adjust the control's translate transforms so that the image will be // centered on the same point on the graph that the control is centered // on. oGraphImageCenterer.CenterGraphImage(imageSize); oFixedPage.Children.Add(this); oFixedPage.Measure(imageSize); oFixedPage.Arrange(new System.Windows.Rect( new System.Windows.Point(), imageSize)); oFixedPage.UpdateLayout(); ((System.Windows.Markup.IAddChild)oPageContent).AddChild( oFixedPage); oFixedDocument.Pages.Add(oPageContent); try { XpsDocument oXpsDocument = new XpsDocument(fileName, FileAccess.Write); XpsDocumentWriter oXpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(oXpsDocument); oXpsDocumentWriter.Write(oFixedDocument); oXpsDocument.Close(); } finally { // Reconnect the NodeXLControl to its original parent. Reset the // size to Auto in the process. oFixedPage.Children.Remove(this); this.Width = Double.NaN; this.Height = Double.NaN; oGraphImageCenterer.RestoreCenter(); oParentChildren.Insert(iChildIndex, this); // The graph may have shrunk when it was connected to the // FixedPage, and even though it will be expanded to its original // dimensions when UpdateLayout() is called below, the layout may // have lost "resolution" and the results may be poor. // // Fix this by restoring the original layout and redrawing the // graph. this.UpdateLayout(); oLayoutSaver.RestoreLayout(); this.DrawGraph(false); } }