/// <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 SelectItem(CompletionListItem item) { if (selectedItem != null) { selectedItem.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)246, (byte)246, (byte)246)); } this.selectedItem = item; this.selectedItem.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)112, (byte)183, (byte)255)); //this.selectedItem.Corner //this.toolTip.Content = item.original.Descripti on; this.border2.Child = (UIElement)item.original.Description; this.scroller.ScrollToVerticalOffset(this.selectedItem.ActualHeight * items.IndexOf(item) - this.Height / 2); }
/// <summary> /// If conditions satisfies then remove equation from list and calls DeleteChart event. /// </summary> /// <param name="sender"></param> /// <param name="ChoosedClass"></param> private void Equation_DeleteEvent(object sender, EquationUI ChoosedClass) { if (!(sender is Button)) { throw new ArgumentException(); } Grid myGrid = new Grid(); UIElementCollection allElements = EquationListStack.Children; foreach (var grid in allElements) { if (grid is Grid) { if ((grid as Grid).Children.Contains(sender as Button)) { myGrid = grid as Grid; } } } if (EquationListStack.Children.Count < 2 || allElements.IndexOf(myGrid) == allElements.Count - 1) { MessageBox.Show("Cannot Delete This Field!", "Error"); } else { EquationListStack.Children.Remove(myGrid); Equations.Remove(ChoosedClass); DeleteChart(this, ChoosedClass); } }
protected override Size ArrangeOverride(Size arrangeSize) { UIElementCollection internalChildren = base.InternalChildren; int count = internalChildren.Count; // If ChildToFill is not specified, set it to the last child int childToFillIndex = ChildToFill == null ? count - 1 : internalChildren.IndexOf(ChildToFill); double y = 0.0; Rect rectForFill = new Rect(0, 0, arrangeSize.Width, arrangeSize.Height); if (childToFillIndex != -1) { // Arrange elements before ChildToFill in sequence for (int i = 0; i < childToFillIndex + 1; i++) { UIElement element = internalChildren[i]; if (element != null) { Size desiredSize = element.DesiredSize; Rect finalRect = new Rect(0, y, Math.Max(0.0, arrangeSize.Width), Math.Max(0.0, arrangeSize.Height - y)); if (i < childToFillIndex) { finalRect.Height = desiredSize.Height; y += desiredSize.Height; element.Arrange(finalRect); } else { // The rect for the rest of children rectForFill = finalRect; } } } y = 0.0; // Arrange the elements after ChildToFill in negative sequence(Including ChildToFill) for (int i = count - 1; i > childToFillIndex; i--) { UIElement element = internalChildren[i]; if (element != null) { Size desiredSize = element.DesiredSize; Rect finalRect = new Rect(0, arrangeSize.Height - y - desiredSize.Height, Math.Max(0.0, arrangeSize.Width), Math.Max(0.0, desiredSize.Height)); element.Arrange(finalRect); y += desiredSize.Height; } } rectForFill.Height -= y; InternalChildren[childToFillIndex].Arrange(rectForFill); } return(arrangeSize); }
private void RemoveInternalChild(UIElement child) { UIElementCollection children = InternalChildren; int index = children.IndexOf(child); if (index != -1) { RemoveInternalChildRange(index, 1); } }
public List <UIElement> GetChildren(UIElementCollection collection) { List <UIElement> children = new List <UIElement>(); int start; int end; if (Start != null && End != null) { start = collection.IndexOf(Start); end = collection.IndexOf(End); for (int i = start; i <= end; i++) { children.Add(collection[i]); } } return(children); }
/// <summary> /// 获取需要作为检索字典键值的TextBlock /// </summary> /// <param name="sender"></param> /// <param name="StackPanel_Main"></param> /// <param name="collection"></param> /// <returns></returns> public static UIElement GetTextBlock(object sender, StackPanel StackPanel_Main, UIElementCollection collection) { //ComboBox情况单一,兄弟元素就是所需的TextBlock if (((object)sender).GetType().Name == "ComboBox") { return((TextBlock)VisualTreeHelper.GetChild(StackPanel_Main, collection.IndexOf((ComboBox)sender) - 1));//IndexOf-1就是兄弟元素 } UIElement child; TextBox textBox = (TextBox)sender; if (textBox.Parent as StackPanel != null)//是普通的TextBox,寻找兄弟元素即可 { child = textBox; } else//是自定义控件的TextBox,层级如下 TextBox->Grid->TextBoxWithImg->StackPanel { child = GetParent(sender as UIElement, 2);//所以只需要循环两次就可以得到作为子元素的自定义控件 } return((TextBlock)VisualTreeHelper.GetChild(StackPanel_Main, collection.IndexOf(child) - 1)); }
public int GetButtonIndex(object obj) { Button btn = obj as Button; if (btn == null) { return(-1); } int num = buttons.IndexOf(btn); return(num); }
public void CalculateGlobalIndex(UIElementCollection elements) { int i; int elementIndex = elements.IndexOf(Element); GlobalIndex = Index; for (i = 0; i < elementIndex; i++) { GlobalIndex += (elements[i] is TextBlockPlus ? ((TextBlockPlus)elements[i]).Text.Length : 1); } }
public static bool IndexOf(this UIElementCollection collection, UIElement element, out int index) { int i = collection.IndexOf(element); if (i >= 0) { index = i; return(true); } else { index = 0; return(false); } }
public void CalculatePositionFromGlobalIndex(UIElementCollection elements) { int current = 0; int step; bool broken = false; int hitIndex; int i; if (elements.Count > 0) { Element = elements[0]; for (i = 0; i < elements.Count; i++) { step = (elements[i] is TextBlockPlus ? elements[i].ToString().Length : 1); if (GlobalIndex >= current && GlobalIndex < current + step) { Element = elements[i]; Index = GlobalIndex - current; broken = true; break; } current += step; } if (!broken && GlobalIndex == current) { Element = elements[elements.Count - 1]; Index = (Element is TextBlockPlus ? ((TextBlockPlus)Element).Text.Length : 0); broken = true; } if (broken && Index == 0) { hitIndex = elements.IndexOf(Element); if (hitIndex > 0) { if (elements[hitIndex - 1] is TextBlockPlus) { Element = elements[hitIndex - 1]; Index = ((TextBlockPlus)Element).Text.Length; } } } } }
protected override void OnChecked(RoutedEventArgs e) { base.OnChecked(e); UIElementCollection group = ((this.Parent as ServerGroupPanel)?.Parent as ServerGroupRootPanel)?.Children; if (group == null) { return; } int idx = group.IndexOf(this.Parent as ServerGroupPanel); if (idx < 0) { return; } int i; for (i = 0; i < idx; i++) { if (group[i] as ServerGroupPanel != null) { (group[i] as ServerGroupPanel).VerticalAlignment = VerticalAlignment.Top; } (group[i] as ServerGroupPanel).IsChecked = false; } if (group[i] as ServerGroupPanel != null) { (group[i++] as ServerGroupPanel).VerticalAlignment = VerticalAlignment.Stretch; } for (; i < group.Count; i++) { if (group[i] as ServerGroupPanel != null) { (group[i] as ServerGroupPanel).VerticalAlignment = VerticalAlignment.Bottom; } (group[i] as ServerGroupPanel).IsChecked = false; } ServerListBox slb = (this.Parent as ServerGroupPanel)?.slb; if (slb != null) { slb.Visibility = Visibility.Visible; } }
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"); }
protected override Size ArrangeOverride(Size arrangeSize) { UIElementCollection internalChildren = base.InternalChildren; int count = internalChildren.Count; int childToFillIndex = (this.ChildToFill == null) ? (count - 1) : internalChildren.IndexOf(this.ChildToFill); double y = 0.0; Rect rectForFill = new Rect(0.0, 0.0, arrangeSize.Width, arrangeSize.Height); if (childToFillIndex != -1) { for (int i = 0; i < childToFillIndex + 1; i++) { UIElement element = internalChildren[i]; if (element != null) { Size desiredSize = element.DesiredSize; Rect finalRect = new Rect(0.0, y, Math.Max(0.0, arrangeSize.Width), Math.Max(0.0, arrangeSize.Height - y)); if (i < childToFillIndex) { finalRect.Height = desiredSize.Height; y += desiredSize.Height; element.Arrange(finalRect); } else { rectForFill = finalRect; } } } y = 0.0; for (int i = count - 1; i > childToFillIndex; i--) { UIElement element = internalChildren[i]; if (element != null) { Size desiredSize = element.DesiredSize; Rect finalRect = new Rect(0.0, arrangeSize.Height - y - desiredSize.Height, Math.Max(0.0, arrangeSize.Width), Math.Max(0.0, desiredSize.Height)); element.Arrange(finalRect); y += desiredSize.Height; } } rectForFill.Height -= y; base.InternalChildren[childToFillIndex].Arrange(rectForFill); } return(arrangeSize); }
private void OnFullSplit(object o, SplitEventArgs e) { UIElementCollection previewChildren = Preview.Children; UIElement splitee = (UIElement)o; GridLayoutModel model = Model; int spliteeIndex = previewChildren.IndexOf(splitee); int rows = model.Rows; int cols = model.Columns; _startRow = -1; _startCol = -1; for (int row = rows - 1; row >= 0; row--) { for (int col = cols - 1; col >= 0; col--) { if (model.CellChildMap[row, col] == spliteeIndex) { _dragHandles.RemoveDragHandles(); _startRow = _endRow = row; _startCol = _endCol = col; ExtendRangeToHaveEvenCellEdges(); for (row = _startRow; row <= _endRow; row++) { for (col = _startCol; col <= _endCol; col++) { if ((row != _startRow) || (col != _startCol)) { model.CellChildMap[row, col] = AddZone(); } } } OnGridDimensionsChanged(); return; } } } }
public static int CalculateDropIndex(Panel panel, UIElementCollection children, Orientation orientation, Point position) { HitTestResult HitTestResult = VisualTreeHelper.HitTest(panel, position); DependencyObject HitItem; if (HitTestResult != null) { DependencyObject[] Ancestors = VisualTreeHelperEx.GetVisualAncestors(HitTestResult.VisualHit, panel); HitItem = Ancestors.Length >= 1 ? Ancestors[1] : null; } else { HitItem = null; } if (HitItem is UIElement) { int ItemIndex = children.IndexOf((UIElement)HitItem); Rect Bounds = ((Visual)HitItem).TransformToAncestor(panel).TransformBounds(VisualTreeHelperEx.GetBounds((Visual)HitItem)); Rect FirstHalfBounds = orientation == Orientation.Vertical ? new Rect(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height / 2) : new Rect(Bounds.Left, Bounds.Top, Bounds.Width / 2, Bounds.Height); if (FirstHalfBounds.Contains(position)) { return(ItemIndex); } else { return(ItemIndex + 1); } } else { // Hit cannot be processed or is on the panel -> return index to insert at the end return(children.Count); } }
public static void RateValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { Rate parent = sender as Rate; int rateValue = (int)e.NewValue; UIElementCollection stars = parent.StarsGrid.Children; foreach (var b in stars) { ((Button)b).Background = new SolidColorBrush(parent.NotRatedColor); } foreach (var b in stars) { if (stars.IndexOf((Button)b) == rateValue) { break; } ((Button)b).Background = new SolidColorBrush(parent.RatedColor); } }
/// <summary> /// When overridden in a derived class, positions child elements and determines a size for a <see cref="T:System.Windows.FrameworkElement"/> derived class. /// </summary> /// <returns> /// The actual size used. /// </returns> /// <param name="finalSize">The final area within the parent that this element should use to arrange itself and its children.</param> protected override Size ArrangeOverride(Size finalSize) { this.EnsureSynchronisationRootExists(); double CaptionWidth = this.SynchronisationRoot.CaptionWidth; double ControlWidth = finalSize.Width - this.InnerColumnMargin - CaptionWidth; double Top = 0; double InnerRowMargin = this.InnerRowMargin; UIElementCollection Controls = this.Children; foreach (UIElement Control in Controls) { UIElement Caption = this.GetCaptionForControl(Control); bool IsLastControl = Controls.IndexOf(Control) == Controls.Count - 1; Size ControlSize = Control.DesiredSize; Size CaptionSize = Caption?.DesiredSize ?? new Size(0, 0); double RowHeight = IsLastControl ? finalSize.Height - Top : Math.Max(CaptionSize.Height, ControlSize.Height); if (Caption != null) { Caption.Arrange(new Rect(0, Top, CaptionWidth, RowHeight)); Control.Arrange(new Rect(CaptionWidth + this.InnerColumnMargin, Top, ControlWidth, RowHeight)); } else { //there is no caption, This means, the control shall have full width Control.Arrange(new Rect(0, Top, finalSize.Width, RowHeight)); } Top += RowHeight + InnerRowMargin; } return(finalSize); }
private void OpenRandomFields(Button sender) { UIElementCollection collection = gridMain.Children; int index = collection.IndexOf(sender); int max = r.Next(index, collection.Count); for (int i = index; i < max; i++) { Button b = collection[i] as Button; int x = Grid.GetRow(b); int y = Grid.GetColumn(b); Position p = new Position(x, y); if (bombPositions.Contains(p)) { break; } else { SetImageForMapItem(x, y, b); openedPositions.Add(p); } } }
/// <inheritdoc /> public int IndexOf(Inline item) => _collection.IndexOf(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); } }
private void OnSplit(object o, SplitEventArgs e) { MergeCancelClick(null, null); UIElementCollection previewChildren = Preview.Children; GridZone splitee = (GridZone)o; int spliteeIndex = previewChildren.IndexOf(splitee); GridLayoutModel model = Model; int rows = model.Rows; int cols = model.Columns; Tuple <int, int> rowCol = _data.RowColByIndex(spliteeIndex); int foundRow = rowCol.Item1; int foundCol = rowCol.Item2; int newChildIndex = AddZone(); double offset = e.Offset; double space = e.Space; if (e.Orientation == Orientation.Vertical) { if (splitee.VerticalSnapPoints != null) { offset += Canvas.GetLeft(splitee); int count = splitee.VerticalSnapPoints.Length; bool foundExistingSplit = false; int splitCol = foundCol; for (int i = 0; i <= count; i++) { if (foundExistingSplit) { int walkRow = foundRow; while ((walkRow < rows) && (_data.GetIndex(walkRow, foundCol + i) == spliteeIndex)) { _data.SetIndex(walkRow++, foundCol + i, newChildIndex); } } if (_data.ColumnBottom(foundCol + i) == offset) { foundExistingSplit = true; splitCol = foundCol + i; // use existing division } } if (foundExistingSplit) { _data.ReplaceIndicesToMaintainOrder(Preview.Children.Count); _dragHandles.UpdateForExistingVerticalSplit(model, foundRow, splitCol); OnGridDimensionsChanged(); return; } while (_data.ColumnBottom(foundCol) < offset) { foundCol++; } offset -= _data.ColumnTop(foundCol); } _dragHandles.UpdateAfterVerticalSplit(foundCol); _data.SplitColumn(foundCol, spliteeIndex, newChildIndex, space, offset, ActualWidth); _dragHandles.AddDragHandle(Orientation.Vertical, foundRow, foundCol, model); } else { // Horizontal if (splitee.HorizontalSnapPoints != null) { offset += Canvas.GetTop(splitee); int count = splitee.HorizontalSnapPoints.Length; bool foundExistingSplit = false; int splitRow = foundRow; for (int i = 0; i <= count; i++) { if (foundExistingSplit) { int walkCol = foundCol; while ((walkCol < cols) && (_data.GetIndex(foundRow + i, walkCol) == spliteeIndex)) { _data.SetIndex(foundRow + i, walkCol++, newChildIndex); } } if (_data.RowEnd(foundRow + i) == offset) { foundExistingSplit = true; splitRow = foundRow + i; // use existing division } } if (foundExistingSplit) { _data.ReplaceIndicesToMaintainOrder(Preview.Children.Count); _dragHandles.UpdateForExistingHorizontalSplit(model, splitRow, foundCol); OnGridDimensionsChanged(); return; } while (_data.RowEnd(foundRow) < offset) { foundRow++; } offset -= _data.RowStart(foundRow); } _dragHandles.UpdateAfterHorizontalSplit(foundRow); _data.SplitRow(foundRow, spliteeIndex, newChildIndex, space, offset, ActualHeight); _dragHandles.AddDragHandle(Orientation.Horizontal, foundRow, foundCol, model); } Size actualSize = new Size(ActualWidth, ActualHeight); ArrangeGridRects(actualSize); }
Composite ( Double compositeWidth, Double compositeHeight, String headerText, String footerText, System.Drawing.Font headerFooterFont, IEnumerable <LegendControlBase> legendControls ) { Debug.Assert(compositeWidth > 0); Debug.Assert(compositeHeight > 0); Debug.Assert(headerFooterFont != null); Debug.Assert(legendControls != null); AssertValid(); // Note: // // Don't try taking a shortcut by using // NodeXLControl.CopyGraphToBitmap() to get an image of the graph and // then compositing the image with the other elements. That would work // if the caller were creating an image, but if it were creating an XPS // document, the graph would no longer be scalable. Double dScreenDpi = WpfGraphicsUtil.GetScreenDpi(m_oNodeXLControl).Width; // The NodeXLControl can't be a child of two logical trees, so // disconnect it from its parent after saving the current vertex // locations. m_oLayoutSaver = new LayoutSaver(m_oNodeXLControl.Graph); Debug.Assert(m_oNodeXLControl.Parent is Panel); m_oParentPanel = (Panel)m_oNodeXLControl.Parent; UIElementCollection oParentChildren = m_oParentPanel.Children; m_iChildIndex = oParentChildren.IndexOf(m_oNodeXLControl); oParentChildren.Remove(m_oNodeXLControl); m_oGraphImageScaler = new GraphImageScaler(m_oNodeXLControl); m_oGraphImageCenterer = new NodeXLControl.GraphImageCenterer( m_oNodeXLControl); // The header and footer are rendered as Label controls. The legend is // rendered as a set of Image controls. Label oHeaderLabel, oFooterLabel; IEnumerable <Image> oLegendImages; Double dHeaderHeight, dTotalLegendHeight, dFooterHeight; CreateHeaderOrFooterLabel(headerText, compositeWidth, headerFooterFont, out oHeaderLabel, out dHeaderHeight); CreateLegendImages(legendControls, compositeWidth, out oLegendImages, out dTotalLegendHeight); CreateHeaderOrFooterLabel(footerText, compositeWidth, headerFooterFont, out oFooterLabel, out dFooterHeight); m_oNodeXLControl.Width = compositeWidth; m_oNodeXLControl.Height = Math.Max(10, compositeHeight - dHeaderHeight - dTotalLegendHeight - dFooterHeight); // Adjust the control's graph scale so that the graph's vertices and // edges will be the same relative size in the composite that they are // in the control. m_oGraphImageScaler.SetGraphScale( (Int32)WpfGraphicsUtil.WpfToPx(compositeWidth, dScreenDpi), (Int32)WpfGraphicsUtil.WpfToPx(m_oNodeXLControl.Height, dScreenDpi), dScreenDpi); // Adjust the NodeXLControl's translate transforms so that the // composite will be centered on the same point on the graph that the // NodeXLControl is centered on. m_oGraphImageCenterer.CenterGraphImage(new Size(compositeWidth, m_oNodeXLControl.Height)); StackPanel oStackPanel = new StackPanel(); UIElementCollection oStackPanelChildren = oStackPanel.Children; // To avoid a solid black line at the bottom of the header or the top // of the footer, which is caused by rounding errors, make the // StackPanel background color the same as the header and footer. oStackPanel.Background = HeaderFooterBackgroundBrush; if (oHeaderLabel != null) { oStackPanelChildren.Add(oHeaderLabel); } // Wrap the NodeXLControl in a Grid to clip it. m_oGrid = new Grid(); m_oGrid.Width = m_oNodeXLControl.Width; m_oGrid.Height = m_oNodeXLControl.Height; m_oGrid.ClipToBounds = true; m_oGrid.Children.Add(m_oNodeXLControl); oStackPanelChildren.Add(m_oGrid); foreach (Image oLegendImage in oLegendImages) { oStackPanelChildren.Add(oLegendImage); } if (oFooterLabel != null) { oStackPanelChildren.Add(oFooterLabel); } Size oCompositeSize = new Size(compositeWidth, compositeHeight); Rect oCompositeRectangle = new Rect(new Point(), oCompositeSize); oStackPanel.Measure(oCompositeSize); oStackPanel.Arrange(oCompositeRectangle); oStackPanel.UpdateLayout(); return(oStackPanel); }
private void OnSplit(object o, SplitEventArgs e) { UIElementCollection previewChildren = Preview.Children; GridZone splitee = (GridZone)o; int spliteeIndex = previewChildren.IndexOf(splitee); GridLayoutModel model = Model; int rows = model.Rows; int cols = model.Columns; int foundRow = -1; int foundCol = -1; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { if (model.CellChildMap[row, col] == spliteeIndex) { foundRow = row; foundCol = col; break; } } if (foundRow != -1) { break; } } int newChildIndex = AddZone(); double offset = e.Offset; if (e.Orientation == Orientation.Vertical) { if (splitee.VerticalSnapPoints != null) { offset += Canvas.GetLeft(splitee); int count = splitee.VerticalSnapPoints.Length; bool foundExistingSplit = false; for (int i = 0; i <= count; i++) { if (foundExistingSplit) { int walkRow = foundRow; while ((walkRow < rows) && (model.CellChildMap[walkRow, foundCol + i] == spliteeIndex)) { model.CellChildMap[walkRow++, foundCol + i] = newChildIndex; } } if (_colInfo[foundCol + i].End == offset) { foundExistingSplit = true; // use existing division } } if (foundExistingSplit) { OnGridDimensionsChanged(); return; } while (_colInfo[foundCol].End < offset) { foundCol++; } offset -= _colInfo[foundCol].Start; } AddDragHandle(Orientation.Vertical, cols - 1); cols++; int[,] newCellChildMap = new int[rows, cols]; int[] newColPercents = new int[cols]; RowColInfo[] newColInfo = new RowColInfo[cols]; int sourceCol = 0; for (int col = 0; col < cols; col++) { for (int row = 0; row < rows; row++) { if ((col > foundCol) && (model.CellChildMap[row, sourceCol] == spliteeIndex)) { newCellChildMap[row, col] = newChildIndex; } else { newCellChildMap[row, col] = model.CellChildMap[row, sourceCol]; } } if (col != foundCol) { sourceCol++; } } model.CellChildMap = newCellChildMap; sourceCol = 0; for (int col = 0; col < cols; col++) { if (col == foundCol) { RowColInfo[] split = _colInfo[col].Split(offset); newColPercents[col] = split[0].Percent; newColInfo[col++] = split[0]; newColPercents[col] = split[1].Percent; newColInfo[col] = split[1]; sourceCol++; } else { newColPercents[col] = model.ColumnPercents[sourceCol]; newColInfo[col] = _colInfo[sourceCol++]; } } _colInfo = newColInfo; model.ColumnPercents = newColPercents; model.Columns++; } else { // Horizontal if (splitee.HorizontalSnapPoints != null) { offset += Canvas.GetTop(splitee); int count = splitee.HorizontalSnapPoints.Length; bool foundExistingSplit = false; for (int i = 0; i <= count; i++) { if (foundExistingSplit) { int walkCol = foundCol; while ((walkCol < cols) && (model.CellChildMap[foundRow + i, walkCol] == spliteeIndex)) { model.CellChildMap[foundRow + i, walkCol] = newChildIndex; } } if (_rowInfo[foundRow + i].End == offset) { foundExistingSplit = true; // use existing division } } if (foundExistingSplit) { OnGridDimensionsChanged(); return; } while (_rowInfo[foundRow].End < offset) { foundRow++; } offset -= _rowInfo[foundRow].Start; } AddDragHandle(Orientation.Horizontal, rows - 1); rows++; int[,] newCellChildMap = new int[rows, cols]; int[] newRowPercents = new int[rows]; RowColInfo[] newRowInfo = new RowColInfo[rows]; int sourceRow = 0; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { if ((row > foundRow) && (model.CellChildMap[sourceRow, col] == spliteeIndex)) { newCellChildMap[row, col] = newChildIndex; } else { newCellChildMap[row, col] = model.CellChildMap[sourceRow, col]; } } if (row != foundRow) { sourceRow++; } } model.CellChildMap = newCellChildMap; sourceRow = 0; for (int row = 0; row < rows; row++) { if (row == foundRow) { RowColInfo[] split = _rowInfo[row].Split(offset); newRowPercents[row] = split[0].Percent; newRowInfo[row++] = split[0]; newRowPercents[row] = split[1].Percent; newRowInfo[row] = split[1]; sourceRow++; } else { newRowPercents[row] = model.RowPercents[sourceRow]; newRowInfo[row] = _rowInfo[sourceRow++]; } } _rowInfo = newRowInfo; model.RowPercents = newRowPercents; model.Rows++; } }
public int IndexOf(ListBoxItem item) { return(_items.IndexOf(item)); }