public void Draw(UIElementCollection children) { if (!isAlive) return; DateTime cur = DateTime.Now; foreach (var segment in segments) { PlayerUtils.Segment seg = segment.Value.GetEstimatedSegment(cur); if (seg.IsCircle()) { var circle = new Ellipse(); circle.Width = seg.radius * 2; circle.Height = seg.radius * 2; circle.SetValue(Canvas.LeftProperty, seg.x1 - seg.radius); circle.SetValue(Canvas.TopProperty, seg.y1 - seg.radius); circle.Stroke = brJoints; circle.StrokeThickness = 1; circle.Fill = brBones; children.Add(circle); } } // Remove unused players after 1/2 second. if (DateTime.Now.Subtract(lastUpdated).TotalMilliseconds > 500) isAlive = false; }
public static double ItemCount(CalendarAppointmentItem currentApp, UIElementCollection children) { double count = 0; foreach (UIElement child in children) { if (child is CalendarAppointmentItem) { var currentChild = child as CalendarAppointmentItem; var cStart = currentApp.GetValue(TimeSlotPanel.StartTimeProperty) as DateTime?; var cEnd = currentApp.GetValue(TimeSlotPanel.EndTimeProperty) as DateTime?; var toTest = new DateRange(cStart.Value, cEnd.Value); var aStart = currentChild.GetValue(TimeSlotPanel.StartTimeProperty) as DateTime?; var aEnd = currentChild.GetValue(TimeSlotPanel.EndTimeProperty) as DateTime?; var current = new DateRange(aStart.Value, aEnd.Value); if (toTest.Overlaps(current)) { count++; } } } return count; }
public SudokuCell(UIElementCollection panel, int bsize, SudokuBoard sb) { this.sb = sb; this.bsize = bsize; this.children = new List<SudokuCell>(); this.panel = panel; isLeaf = false; int size = bsize * bsize; int bss = size * size; int[] data = new int[bss]; for (var i = 0; i < bss; i++) data[i] = i; for (var i = 0; i < bsize; i++) { for (var j = 0; j < bsize; j++) { var t = new List<int>(); for (var k = i * bsize; k < (i + 1) * bsize; k++) { for (var l = j * bsize; l < (j + 1) * bsize; l++) { t.Add(data[k * size + l]); } } var sc = new SudokuCell(this.panel, t.ToArray(), j, i, bsize, sb); children.Add(sc); } } }
public Viewport3D() { this._renderTarget = new Canvas(); this.currentOrderedTriangles = this._renderTarget.Children; this.Content = _renderTarget; this.SizeChanged += new SizeChangedEventHandler(Viewport3D_SizeChanged); }
private static void AddPasswordBox( UIElementCollection labelCollection, UIElementCollection inputCollection, UIElementCollection checkBoxCollection, string content, object dataContext, string key, int index) { var viewModel = (INotifyPropertyChanged)dataContext; labelCollection.Add(new Label() { Content = content }); var control = new PasswordBox() { DataContext = dataContext, TabIndex = index }; var parameters = (IDictionary<string, string>)((dynamic)dataContext).Dictionary; control.Password = parameters[key]; PropertyChangedEventHandler onSourceChanged = (sender, e) => { if (e.PropertyName != key) { return; } if (control.Password == parameters[key]) { return; } control.Password = parameters[key]; }; viewModel.PropertyChanged += onSourceChanged; control.PasswordChanged += (sender, e) => { if (parameters[key] != control.Password) { parameters[key] = control.Password; } }; control.Unloaded += (sender, e) => viewModel.PropertyChanged -= onSourceChanged; inputCollection.Add(new UserControl() { Content = control }); checkBoxCollection.Add(new FrameworkElement()); }
public TreeGridViewRowPresenter() { _childs = new UIElementCollection(this, this); DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(ColumnsProperty, typeof(TreeGridViewRowPresenter)); if (dpd != null) dpd.AddValueChanged(this, (s, e) => EnsureLines()); }
public ElementMovOrRes(CommandStack commandStack, UIElementCollection selection, Rect newrect, Rect oldrect, int editingOperationCount) : base(commandStack) { _selection = selection; _newrect = newrect; _oldrect = oldrect; _editingOperationCount = editingOperationCount; }
private void AddColor(System.Windows.Controls.UIElementCollection collection) { foreach (System.Windows.Controls.Label label in collection) { String str = label.Content.ToString(); double value = 1; if (str.Equals("½")) { value = 0.5; } else if (str.Equals("¼")) { value = 0.25; } else if (!str.Equals("")) { value = double.Parse(str); } if (label.Content.ToString() != "" && value < 1) { label.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(100, 211, 111, 106)); } else if (label.Content.ToString() != "" && value > 1) { label.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(100, 169, 215, 157)); } else { label.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)); } } }
/// <summary> /// Creates the Viewport3DDecorator /// </summary> public Viewport3DDecorator() { _preViewportChildren = new UIElementCollection(this, this); _postViewportChildren = new UIElementCollection(this, this); _content = null; }
public void Draw(UIElementCollection children) { foreach (SingleVortex sv in reds) children.Add(sv); foreach (SingleVortex sv in blues) children.Add(sv); }
private void AddAllStrokesAtOriginalIndex(UIElementCollection toBeAdded) { foreach (UIElement elm in toBeAdded) { //int strokeIndex = (int)elm.GetPropertyData(STROKE_INDEX_PROPERTY); //if (strokeIndex > _commandStack.StrokeCollection.Count) // strokeIndex = _commandStack.StrokeCollection.Count; _commandStack.ElementCollection.Add(elm); } }
public ImFormsMgr(WpfElementList collection) { InteractedElementId = null; ImElements = new Dictionary <string, ImElement>(); TCS = new TaskCompletionSource <bool>(); CurrentSortKey = 0; DisplayedElements = collection; }
public Game1(MainWindow main) { this.main = main; InitializeComponent(); ttt.CreatePlayer(new Player("Ann", P1)); ttt.CreatePlayer(new Player("Ben", P2)); controls = MainGrid.Children; }
/// <summary> /// Initializes a new instance of the <see cref="Viewport3DDecorator"/> class. /// Creates the Viewport3DDecorator /// </summary> protected Viewport3DDecorator() { // create the two lists of children this._preViewportChildren = new UIElementCollection(this, this); this._postViewportChildren = new UIElementCollection(this, this); // no content yet this._content = null; }
/// <summary> /// Creates the Viewport3DDecorator /// </summary> public Viewport3DDecorator() { // create the two lists of children _preViewportChildren = new UIElementCollection(this, this); _postViewportChildren = new UIElementCollection(this, this); // no content yet _content = null; }
public ElementAddOrRem(CommandStack commandStack, InkCanvasEditingMode editingMode, UIElementCollection added, UIElementCollection removed, int editingOperationCount) : base(commandStack) { _editingMode = editingMode; _added = added; _removed = removed; _editingOperationCount = editingOperationCount; }
/// <summary> /// Calculates the height of column. /// </summary> /// <param name="i">The starting point.</param> /// <param name="startOfColumnElementIndex">Start index of the of column element.</param> /// <param name="endOfColumnElementIndex">End index of the of column element.</param> /// <param name="children">The children.</param> /// <returns></returns> public static int CalculateHeightOfColumn(int i, int[] startOfColumnElementIndex, int[] endOfColumnElementIndex, UIElementCollection children) { var thisColHeight = 0; for (var j = startOfColumnElementIndex[i]; j <= endOfColumnElementIndex[i]; j++) { var height = (int)children[j].DesiredSize.Height; thisColHeight += height; } return thisColHeight; }
private static void AddTextBox( UIElementCollection labelCollection, UIElementCollection inputCollection, UIElementCollection checkBoxCollection, string labelText, object dataContext, string key, int tabIndex) { labelCollection.Add(new Label() { Content = labelText }); var control = new TextBox() { DataContext = dataContext, TabIndex = tabIndex }; control.SetBinding(TextBox.TextProperty, new Binding(key)); inputCollection.Add(new UserControl() { Content = control }); checkBoxCollection.Add(new FrameworkElement()); }
private BloodType getBloodType(UIElementCollection radioButtonList) { //convert the selected radioButton to a BloodType BloodType b = BloodType.O; foreach (RadioButton r in radioButtonList) { if ((bool)r.IsChecked) b = (BloodType)Enum.Parse(typeof(BloodType), r.Content.ToString()); } return b; }
public MainWindow() { generator = new Random(10000000); InitializeComponent(); buttons = canvasKeyboard.Children; foreach (ContentControl ctrl in buttons) ctrl.RenderTransform = new TranslateTransform(); labels = panelDisplay.Children; this.state = true; ViewModel vm = new ViewModel(this); }
public PivotView(PivotControl parent) { Parent = parent; LayoutRoot = Parent.LayoutRoot; HeadersPanel = Parent.HeadersPanel; Headers = HeadersPanel.Children; Items = Parent.Items; HeadersHost.Transform = new TranslateTransform(); ItemsHost.Transform = new TranslateTransform(); }
private void SetBlocksMouseEvent( UIElementCollection collection ) { foreach ( UIElement block in collection ) { //block.PreviewMouseLeftButtonDown += new MouseButtonEventHandler( m_dragController.OnPreviewMouseLeftButtonDown ); block.MouseLeftButtonDown += new MouseButtonEventHandler( m_dragController.OnPreviewMouseLeftButtonDown ); block.PreviewMouseMove += new MouseEventHandler( m_dragController.OnPreviewMouseMove ); //block.MouseMove += new MouseEventHandler( m_dragController.OnMouseMove ); block.PreviewMouseLeftButtonUp += new MouseButtonEventHandler( m_dragController.OnPreviewMouseUp ); } }
public TransitionPresenter() { _children = new UIElementCollection(this, null); ContentPresenter currentContent = new ContentPresenter(); _currentHost = new AdornerDecorator(); _currentHost.Child = currentContent; _children.Add(_currentHost); ContentPresenter previousContent = new ContentPresenter(); _previousHost = new AdornerDecorator(); _previousHost.Child = previousContent; }
/// <summary> /// Connect the broadcast to a panel. /// </summary> /// <param name="panel">Panel.</param> public void ConnectPanel(Panel panel) { _children = panel.Children; foreach (UIElement element in _children) { element.MouseLeftButtonDown += BroadcastMouseEvent; element.MouseLeftButtonUp += BroadcastMouseEvent; element.MouseRightButtonDown += BroadcastMouseEvent; element.MouseRightButtonUp += BroadcastMouseEvent; element.MouseMove += BroadcastMouseEvent; } }
public CreateHousehold(string fName, string lName, string pOQ, string gen, Boolean head, string aGroup, string ethnicG, string rel, UIElementCollection toggle) { firstName = fName; lastName = lName; patientOQ = pOQ; headOfHouse = head; gender = gen; ageGroup = aGroup; ethnicGroup = ethnicG; relationToHead = rel; togglePatientProblems = toggle; InitializeComponent(); }
public static void Draw(UIElementCollection children) { if (bannerText == null) return; Label text = bannerText.GetLabel(); if (text == null) { bannerText = null; return; } children.Add(text); }
public Menu(UIElementCollection _menu, string _menuname) { menu = new Canvas(); left = new Canvas(); leftcenter = new Canvas(); center = new Canvas(); rightcenter = new Canvas(); right = new Canvas(); menuName = _menuname; parent = _menu; right.Name = menuName + "Right"; right.Width = 115; right.RenderTransform = new RotateTransform(11); right.Margin = new Thickness(483, 12, 0, 0); rightcenter.Name = menuName + "RightCenter"; rightcenter.Width = 115; rightcenter.RenderTransform = new RotateTransform(5.5); rightcenter.Margin = new Thickness(363, 0, 0, 0); center.Name = menuName + "Center"; center.Width = 115; center.RenderTransform = new RotateTransform(0); center.Margin = new Thickness(243, 0, 0, 0); leftcenter.Name = menuName + "LeftCenter"; leftcenter.Width = 115; leftcenter.RenderTransform = new RotateTransform(-5.5); leftcenter.Margin = new Thickness(123, 12, 0, 0); left.Name = menuName + "Left"; left.Width = 115; left.RenderTransform = new RotateTransform(-11); left.Margin = new Thickness(4, 36, 0, 0); menu.Name = menuName; menu.Height = 145; menu.Width = 600; menu.HorizontalAlignment = HorizontalAlignment.Center; menu.VerticalAlignment = VerticalAlignment.Top; menu.Margin = new Thickness(0,0,0,0); menu.Children.Add(left); menu.Children.Add(leftcenter); menu.Children.Add(center); menu.Children.Add(rightcenter); menu.Children.Add(right); menu.Tag = "unhidden"; }
public override void Draw(UIElementCollection collection) { Ellipse ellipse; if (DrawedElement == null) ellipse = new Ellipse(); else ellipse = (Ellipse)DrawedElement; UpdateProperties(ellipse); LocateShapeOnCanvas(ellipse); if (DrawedElement == null) collection.Add(ellipse); DrawedElement = ellipse; }
public SudokuBoard(UIElementCollection coll) { string file = @"g:\1.txt"; try { sudokee = sm.LoadFromFile(file); } catch (Exception) { MessageBox.Show("Error during loading.", "Error"); } cell = new SudokuCell(coll,sudokee.BaseSize,this); }
public override void Draw(UIElementCollection collection) { Arrow arrow; if (DrawedElement == null) arrow = new Arrow(); else arrow = (Arrow)DrawedElement; UpdateProperties(arrow); LocateShapeOnCanvas(arrow); if (DrawedElement == null) collection.Add(arrow); DrawedElement = arrow; }
public override void Draw(UIElementCollection collection) { Line line; if (DrawedElement == null) line = new Line(); else line = (Line)DrawedElement; UpdateProperties(line); if (DrawedElement == null) collection.Add(line); DrawedElement = line; }
public override void Draw(UIElementCollection collection) { Star star; if (DrawedElement == null) star = new Star(); else star = (Star)DrawedElement; UpdateProperties(star); LocateShapeOnCanvas(star); if (DrawedElement == null) collection.Add(star); DrawedElement = star; }
private void AddColor(System.Windows.Controls.UIElementCollection collection) { foreach (Label label in collection) { if (label.Content.ToString() != "" && double.Parse(label.Content.ToString()) < 1) { label.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 211, 111, 106)); } else if (label.Content.ToString() != "" && double.Parse(label.Content.ToString()) > 1) { label.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 169, 215, 157)); } else { label.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)); } } }
/// <summary> /// Arrange a sequence of elements in a single line. /// </summary> /// <param name="lineStart"> /// Index of the first element in the sequence to arrange. /// </param> /// <param name="lineEnd"> /// Index of the last+1 element in the sequence to arrange. /// </param> /// <param name="directDelta"> /// Optional fixed growth in the primary direction. /// </param> /// <param name="directMaximum"> /// Maximum length in the direct direction. /// </param> /// <param name="indirectOffset"> /// Offset of the line in the indirect direction. /// </param> /// <param name="indirectGrowth"> /// Shared indirect growth of the elements on this line. /// </param> private void ArrangeLine(int lineStart, int lineEnd, double?directDelta, double directMaximum, double indirectOffset, double indirectGrowth) { Orientation o = Orientation; bool isHorizontal = o == Orientation.Horizontal; UIElementCollection children = Children; double directLength = 0.0; double itemCount = 0.0; double itemLength = isHorizontal ? ItemWidth : ItemHeight; if (AlignLastItems && !itemLength.IsNaN()) { // Length is easy to calculate in this case itemCount = Math.Floor(directMaximum / itemLength); directLength = itemCount * itemLength; } else { // Make first pass to calculate the slack space itemCount = lineEnd - lineStart; for (int index = lineStart; index < lineEnd; index++) { // Get the size of the element UIElement element = children[index]; OrientedSize elementSize = new OrientedSize(o, element.DesiredSize.Width, element.DesiredSize.Height); // Determine if we should use the element's desired size or the // fixed item width or height double directGrowth = directDelta != null ? directDelta.Value : elementSize.Direct; // Update total length directLength += directGrowth; } } // Determine slack double directSlack = directMaximum - directLength; double directSlackSlice = directSlack / (itemCount + 1.0); double directOffset = directSlackSlice; // Make second pass to arrange items for (int index = lineStart; index < lineEnd; index++) { // Get the size of the element UIElement element = children[index]; OrientedSize elementSize = new OrientedSize(o, element.DesiredSize.Width, element.DesiredSize.Height); // Determine if we should use the element's desired size or the // fixed item width or height double directGrowth = directDelta != null ? directDelta.Value : elementSize.Direct; // Arrange the element Rect bounds = isHorizontal ? new Rect(directOffset, indirectOffset, directGrowth, indirectGrowth) : new Rect(indirectOffset, directOffset, indirectGrowth, directGrowth); element.Arrange(bounds); // Update offset for next time directOffset += directGrowth + directSlackSlice; } }
// This is internal as an optimization for VirtualizingStackPanel (so it doesn't need to re-query InternalChildren repeatedly) internal static void InsertInternalChild(UIElementCollection children, int index, UIElement child) { children.InsertInternal(index, child); }
// This is internal as an optimization for VirtualizingStackPanel (so it doesn't need to re-query InternalChildren repeatedly) internal static void AddInternalChild(UIElementCollection children, UIElement child) { children.AddInternal(child); }
/// <summary> /// Arranges and sizes the /// <see cref="T:System.Windows.Controls.WrapPanel" /> control and its /// child elements. /// </summary> /// <param name="finalSize"> /// The area within the parent that the /// <see cref="T:System.Windows.Controls.WrapPanel" /> should use /// arrange itself and its children. /// </param> /// <returns> /// The actual size used by the /// <see cref="T:System.Windows.Controls.WrapPanel" />. /// </returns> protected override Size ArrangeOverride(Size finalSize) { // Variables tracking the size of the current line, and the maximum // size available to fill. Note that the line might represent a row // or a column depending on the orientation. Orientation o = Orientation; OrientedSize lineSize = new OrientedSize(o); OrientedSize maximumSize = new OrientedSize(o, finalSize.Width, finalSize.Height); // Determine the constraints for individual items double itemWidth = ItemWidth; double itemHeight = ItemHeight; bool hasFixedWidth = !itemWidth.IsNaN(); bool hasFixedHeight = !itemHeight.IsNaN(); double indirectOffset = 0; double?directDelta = (o == Orientation.Horizontal) ? (hasFixedWidth ? (double?)itemWidth : null) : (hasFixedHeight ? (double?)itemHeight : null); // Measure each of the Children. We will process the elements one // line at a time, just like during measure, but we will wait until // we've completed an entire line of elements before arranging them. // The lineStart and lineEnd variables track the size of the // currently arranged line. UIElementCollection children = Children; int count = children.Count; int lineStart = 0; for (int lineEnd = 0; lineEnd < count; lineEnd++) { UIElement element = children[lineEnd]; // Get the size of the element OrientedSize elementSize = new OrientedSize( o, hasFixedWidth ? itemWidth : element.DesiredSize.Width, hasFixedHeight ? itemHeight : element.DesiredSize.Height); // If this element falls of the edge of the line if (NumericExtensions.IsGreaterThan(lineSize.Direct + elementSize.Direct, maximumSize.Direct)) { // Then we just completed a line and we should arrange it ArrangeLine(lineStart, lineEnd, directDelta, indirectOffset, lineSize.Indirect); // Move the current element to a new line indirectOffset += lineSize.Indirect; lineSize = elementSize; // If the current element is larger than the maximum size if (NumericExtensions.IsGreaterThan(elementSize.Direct, maximumSize.Direct)) { // Arrange the element as a single line ArrangeLine(lineEnd, ++lineEnd, directDelta, indirectOffset, elementSize.Indirect); // Move to a new line indirectOffset += lineSize.Indirect; lineSize = new OrientedSize(o); } // Advance the start index to a new line after arranging lineStart = lineEnd; } else { // Otherwise just add the element to the end of the line lineSize.Direct += elementSize.Direct; lineSize.Indirect = Math.Max(lineSize.Indirect, elementSize.Indirect); } } // Arrange any elements on the last line if (lineStart < count) { ArrangeLine(lineStart, count, directDelta, indirectOffset, lineSize.Indirect); } return(finalSize); }
//------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------- #region Protected Methods /// <summary> /// Override of <seealso cref="FrameworkElement.MeasureOverride" />. /// </summary> /// <param name="constraint">Constraint size is an "upper limit" that the return value should not exceed.</param> /// <returns>The GridViewRowPresenter's desired size.</returns> protected override Size MeasureOverride(Size constraint) { GridViewColumnCollection columns = Columns; if (columns == null) { return(new Size()); } UIElementCollection children = InternalChildren; double maxHeight = 0.0; // Max height of children. double accumulatedWidth = 0.0; // Total width consumed by children. double constraintHeight = constraint.Height; bool desiredWidthListEnsured = false; foreach (GridViewColumn column in columns) { UIElement child = children[column.ActualIndex]; if (child == null) { continue; } double childConstraintWidth = Math.Max(0.0, constraint.Width - accumulatedWidth); if (column.State == ColumnMeasureState.Init || column.State == ColumnMeasureState.Headered) { if (!desiredWidthListEnsured) { EnsureDesiredWidthList(); LayoutUpdated += new EventHandler(OnLayoutUpdated); desiredWidthListEnsured = true; } // Measure child. child.Measure(new Size(childConstraintWidth, constraintHeight)); // As long as this is the first round of measure that has data participate // the width should be ensured // only element on current page paticipates in calculating the shared width if (IsOnCurrentPage) { column.EnsureWidth(child.DesiredSize.Width); } DesiredWidthList[column.ActualIndex] = column.DesiredWidth; accumulatedWidth += column.DesiredWidth; } else if (column.State == ColumnMeasureState.Data) { childConstraintWidth = Math.Min(childConstraintWidth, column.DesiredWidth); child.Measure(new Size(childConstraintWidth, constraintHeight)); accumulatedWidth += column.DesiredWidth; } else // ColumnMeasureState.SpecificWidth { childConstraintWidth = Math.Min(childConstraintWidth, column.Width); child.Measure(new Size(childConstraintWidth, constraintHeight)); accumulatedWidth += column.Width; } maxHeight = Math.Max(maxHeight, child.DesiredSize.Height); } // Reset this flag so that we will re-caculate it on every measure. _isOnCurrentPageValid = false; // reserve space for dummy header next to the last column accumulatedWidth += c_PaddingHeaderMinWidth; return(new Size(accumulatedWidth, maxHeight)); }
// Token: 0x06005698 RID: 22168 RVA: 0x0017F0C4 File Offset: 0x0017D2C4 internal static Size StackMeasureHelper(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size constraint) { Size size = default(Size); UIElementCollection internalChildren = measureElement.InternalChildren; Size availableSize = constraint; bool flag = measureElement.Orientation == Orientation.Horizontal; int num = -1; int i; double num2; if (flag) { availableSize.Width = double.PositiveInfinity; if (measureElement.IsScrolling && measureElement.CanVerticallyScroll) { availableSize.Height = double.PositiveInfinity; } i = (measureElement.IsScrolling ? StackPanel.CoerceOffsetToInteger(scrollData.Offset.X, internalChildren.Count) : 0); num2 = constraint.Width; } else { availableSize.Height = double.PositiveInfinity; if (measureElement.IsScrolling && measureElement.CanHorizontallyScroll) { availableSize.Width = double.PositiveInfinity; } i = (measureElement.IsScrolling ? StackPanel.CoerceOffsetToInteger(scrollData.Offset.Y, internalChildren.Count) : 0); num2 = constraint.Height; } int j = 0; int count = internalChildren.Count; while (j < count) { UIElement uielement = internalChildren[j]; if (uielement != null) { uielement.Measure(availableSize); Size desiredSize = uielement.DesiredSize; double num3; if (flag) { size.Width += desiredSize.Width; size.Height = Math.Max(size.Height, desiredSize.Height); num3 = desiredSize.Width; } else { size.Width = Math.Max(size.Width, desiredSize.Width); size.Height += desiredSize.Height; num3 = desiredSize.Height; } if (measureElement.IsScrolling && num == -1 && j >= i) { num2 -= num3; if (DoubleUtil.LessThanOrClose(num2, 0.0)) { num = j; } } } j++; } if (measureElement.IsScrolling) { Size viewport = constraint; Size extent = size; Vector offset = scrollData.Offset; if (num == -1) { num = internalChildren.Count - 1; } while (i > 0) { double num4 = num2; if (flag) { num4 -= internalChildren[i - 1].DesiredSize.Width; } else { num4 -= internalChildren[i - 1].DesiredSize.Height; } if (DoubleUtil.LessThan(num4, 0.0)) { break; } i--; num2 = num4; } int count2 = internalChildren.Count; int num5 = num - i; if (num5 == 0 || DoubleUtil.GreaterThanOrClose(num2, 0.0)) { num5++; } if (flag) { scrollData.SetPhysicalViewport(viewport.Width); viewport.Width = (double)num5; extent.Width = (double)count2; offset.X = (double)i; offset.Y = Math.Max(0.0, Math.Min(offset.Y, extent.Height - viewport.Height)); } else { scrollData.SetPhysicalViewport(viewport.Height); viewport.Height = (double)num5; extent.Height = (double)count2; offset.Y = (double)i; offset.X = Math.Max(0.0, Math.Min(offset.X, extent.Width - viewport.Width)); } size.Width = Math.Min(size.Width, constraint.Width); size.Height = Math.Min(size.Height, constraint.Height); StackPanel.VerifyScrollingData(measureElement, scrollData, viewport, extent, offset); } return(size); }
public Panel() { Children = new UIElementCollection(this); Children.CollectionChanged += OnChildrenCollectionChanged; }
/// <summary> /// Helper method which implements the stack like measure. /// </summary> internal static Size StackMeasureHelper(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size constraint) { Size stackDesiredSize = new Size(); UIElementCollection children = measureElement.InternalChildren; Size layoutSlotSize = constraint; bool fHorizontal = (measureElement.Orientation == Orientation.Horizontal); int firstViewport; // First child index in the viewport. int lastViewport = -1; // Last child index in the viewport. -1 indicates we have not yet iterated through the last child. double logicalVisibleSpace, childLogicalSize; // // Initialize child sizing and iterator data // Allow children as much size as they want along the stack. // if (fHorizontal) { layoutSlotSize.Width = Double.PositiveInfinity; if (measureElement.IsScrolling && measureElement.CanVerticallyScroll) { layoutSlotSize.Height = Double.PositiveInfinity; } firstViewport = (measureElement.IsScrolling) ? CoerceOffsetToInteger(scrollData.Offset.X, children.Count) : 0; logicalVisibleSpace = constraint.Width; } else { layoutSlotSize.Height = Double.PositiveInfinity; if (measureElement.IsScrolling && measureElement.CanHorizontallyScroll) { layoutSlotSize.Width = Double.PositiveInfinity; } firstViewport = (measureElement.IsScrolling) ? CoerceOffsetToInteger(scrollData.Offset.Y, children.Count) : 0; logicalVisibleSpace = constraint.Height; } // // Iterate through children. // While we still supported virtualization, this was hidden in a child iterator (see source history). // for (int i = 0, count = children.Count; i < count; ++i) { // Get next child. UIElement child = children[i]; if (child == null) { continue; } // Measure the child. child.Measure(layoutSlotSize); Size childDesiredSize = child.DesiredSize; // Accumulate child size. if (fHorizontal) { stackDesiredSize.Width += childDesiredSize.Width; stackDesiredSize.Height = Math.Max(stackDesiredSize.Height, childDesiredSize.Height); childLogicalSize = childDesiredSize.Width; } else { stackDesiredSize.Width = Math.Max(stackDesiredSize.Width, childDesiredSize.Width); stackDesiredSize.Height += childDesiredSize.Height; childLogicalSize = childDesiredSize.Height; } // Adjust remaining viewport space if we are scrolling and within the viewport region. // While scrolling (not virtualizing), we always measure children before and after the viewport. if (measureElement.IsScrolling && lastViewport == -1 && i >= firstViewport) { logicalVisibleSpace -= childLogicalSize; if (DoubleUtil.LessThanOrClose(logicalVisibleSpace, 0.0)) { lastViewport = i; } } } // // Compute Scrolling stuff. // if (measureElement.IsScrolling) { // Compute viewport and extent. Size viewport = constraint; Size extent = stackDesiredSize; Vector offset = scrollData.Offset; // If we have not yet set the last child in the viewport, set it to the last child. if (lastViewport == -1) { lastViewport = children.Count - 1; } // If we or children have resized, it's possible that we can now display more content. // This is true if we started at a nonzero offeset and still have space remaining. // In this case, we loop back through previous children until we run out of space. while (firstViewport > 0) { double projectedLogicalVisibleSpace = logicalVisibleSpace; if (fHorizontal) { projectedLogicalVisibleSpace -= children[firstViewport - 1].DesiredSize.Width; } else { projectedLogicalVisibleSpace -= children[firstViewport - 1].DesiredSize.Height; } // If we have run out of room, break. if (DoubleUtil.LessThan(projectedLogicalVisibleSpace, 0.0)) { break; } // Adjust viewport firstViewport--; logicalVisibleSpace = projectedLogicalVisibleSpace; } int logicalExtent = children.Count; int logicalViewport = lastViewport - firstViewport; // We are conservative when estimating a viewport, not including the last element in case it is only partially visible. // We want to count it if it is fully visible (>= 0 space remaining) or the only element in the viewport. if (logicalViewport == 0 || DoubleUtil.GreaterThanOrClose(logicalVisibleSpace, 0.0)) { logicalViewport++; } if (fHorizontal) { scrollData.SetPhysicalViewport(viewport.Width); viewport.Width = logicalViewport; extent.Width = logicalExtent; offset.X = firstViewport; offset.Y = Math.Max(0, Math.Min(offset.Y, extent.Height - viewport.Height)); } else { scrollData.SetPhysicalViewport(viewport.Height); viewport.Height = logicalViewport; extent.Height = logicalExtent; offset.Y = firstViewport; offset.X = Math.Max(0, Math.Min(offset.X, extent.Width - viewport.Width)); } // Since we can offset and clip our content, we never need to be larger than the parent suggestion. // If we returned the full size of the content, we would always be so big we didn't need to scroll. :) stackDesiredSize.Width = Math.Min(stackDesiredSize.Width, constraint.Width); stackDesiredSize.Height = Math.Min(stackDesiredSize.Height, constraint.Height); // Verify Scroll Info, invalidate ScrollOwner if necessary. VerifyScrollingData(measureElement, scrollData, viewport, extent, offset); } return(stackDesiredSize); }
/// <summary> /// Measure the children /// </summary> /// <param name="availableSize">Size available</param> /// <returns>Size desired</returns> protected override Size MeasureOverride(Size availableSize) { if (ScrollOwner != null) { if (ScrollOwner.ScrollableWidth < HorizontalOffset) SetHorizontalOffset(ScrollOwner.ScrollableWidth); if (ScrollOwner.ScrollableHeight < VerticalOffset) SetVerticalOffset(ScrollOwner.ScrollableHeight); } // We need to access InternalChildren before the generator to work around a bug UIElementCollection children = InternalChildren; IItemContainerGenerator generator = ItemContainerGenerator; ItemsControl itemsControl = ItemsControl.GetItemsOwner(this); TreeViewExItem treeViewItem = itemsControl as TreeViewExItem; TreeViewEx treeView = itemsControl as TreeViewEx ?? treeViewItem.ParentTreeView; Debug(treeViewItem, "Measuring"); double maxWidth = 0; double currentYinItemSystem = 0; if (treeView.IsVirtualizing) { // never forget: virtualization of a tree is an approximation. there are some use cases which theoretically work and others // we try to get it working by estimations. See GetCachedOrEstimatedHeight for more infos. int itemCount = itemsControl.Items.Count; int firstVisibleItemIndex = 0; int lastVisibleItemIndex = itemCount; double itemTop; if (treeViewItem != null) { itemTop = treeViewItem.itemTopInTreeSystem + GetHeightOfHeader(itemsControl); } else { // get the area where items have to be visualized. This is from top to bottom of the visible space in tree system. // We add a little of offset. It seems like it improves estimation of heights. double predictionOffset = 50; double top = VerticalOffset - predictionOffset; if (top < 0) top = 0; treeView.realizationSpace.Top = top; treeView.realizationSpace.Bottom = VerticalOffset + availableSize.Height + predictionOffset; itemTop = GetHeightOfHeader(itemsControl); } int itemGeneratorIndex = 0; bool isPreviousItemVisible = false; IDisposable generatorRun = null; currentYinItemSystem = 0; int childHierarchyLevel = 0; if(treeViewItem != null) childHierarchyLevel = treeViewItem.hierachyLevel + 1; try { // iterate child items for (int i = 0; i < itemCount; i++) { double estimatedHeight = GetCachedOrEstimatedHeight(treeView, childHierarchyLevel); VerticalArea childSpace = new VerticalArea(); childSpace.Top = itemTop + currentYinItemSystem; childSpace.Bottom = childSpace.Top + estimatedHeight; // check if item is possibly visible or could become visible if someone changes expanding of siblings bool isVisibleItem = treeView.realizationSpace.IsWithin(childSpace); if (isVisibleItem) { // we have found a visible item, lets check if its the first visible item. if (!isPreviousItemVisible) { // we found a visible item, lets initialize the visible item section of the loop isPreviousItemVisible = true; firstVisibleItemIndex = i; GeneratorPosition startPos = generator.GeneratorPositionFromIndex(i); itemGeneratorIndex = (startPos.Offset == 0) ? startPos.Index : startPos.Index + 1; generatorRun = generator.StartAt(startPos, GeneratorDirection.Forward, true); } else { itemGeneratorIndex++; } // Get or create the child bool newlyRealized; TreeViewExItem child = generator.GenerateNext(out newlyRealized) as TreeViewExItem; Debug(treeViewItem, "Found visible child: " + child.DataContext); if (newlyRealized) { // Figure out if we need to insert the child at the end or somewhere in the middle AddOrInsertItemToInternalChildren(itemGeneratorIndex, child); child.ParentTreeView = treeView; generator.PrepareItemContainer(child); } else { // The child has already been created, let's be sure it's in the right spot if (child != children[itemGeneratorIndex]) throw new InvalidOperationException("Wrong child was generated"); } if (treeViewItem != null) { child.itemTopInTreeSystem = currentYinItemSystem + itemTop; child.hierachyLevel = treeViewItem.hierachyLevel + 1; } else { child.itemTopInTreeSystem = currentYinItemSystem; child.hierachyLevel = 1; } InvalidateMeasure(child); child.Measure(new Size(double.MaxValue, double.MaxValue)); // add real height to cache double heightOfChild = child.DesiredSize.Height; RegisterHeight(treeView, childHierarchyLevel, heightOfChild); currentYinItemSystem += child.DesiredSize.Height; // save the maximum needed width maxWidth = Math.Max(maxWidth, child.DesiredSize.Width); } else { //Debug(treeViewItem, "Found invisible child: " + i); if (isPreviousItemVisible) { // set last visible index. this is important, to cleanup not anymore used items lastVisibleItemIndex = i; isPreviousItemVisible = false; } // dispose generator run. if we do it after the whole loop, we run in multithreading issues if (generatorRun != null) { generatorRun.Dispose(); generatorRun = null; } currentYinItemSystem += GetCachedOrEstimatedHeight(treeView, childHierarchyLevel); } //Debug(treeViewItem, "Current y for " + i + ": " + currentYinItemSystem); } } finally { //just for safety if (generatorRun != null) { generatorRun.Dispose(); generatorRun = null; } } //Debug("Cleaning all items but " + firstVisibleItemIndex + " to " + lastVisibleItemIndex + " for element " + itemsControl.DataContext); CleanUpItems(firstVisibleItemIndex, lastVisibleItemIndex); } else { //Debug("Virtualization is OFF."); GeneratorPosition startPos = generator.GeneratorPositionFromIndex(0); using (generator.StartAt(startPos, GeneratorDirection.Forward, true)) { for (int i = (startPos.Offset == 0) ? startPos.Index : startPos.Index + 1; i < itemsControl.Items.Count; i++) { // Get or create the child bool newlyRealized; TreeViewExItem child = generator.GenerateNext(out newlyRealized) as TreeViewExItem; if (newlyRealized) { // Figure out if we need to insert the child at the end or somewhere in the middle AddOrInsertItemToInternalChildren(i, child); child.ParentTreeView = treeView ?? treeViewItem.ParentTreeView; generator.PrepareItemContainer(child); } child.Measure(new Size(double.MaxValue, double.MaxValue)); // now get the real height double height = child.DesiredSize.Height; // add real height to current position currentYinItemSystem += height; // save the maximum needed width maxWidth = Math.Max(maxWidth, child.DesiredSize.Width); } } } if (double.IsPositiveInfinity(maxWidth) || double.IsPositiveInfinity(currentYinItemSystem)) { throw new InvalidOperationException("???"); } Extent = new Size(maxWidth, currentYinItemSystem); Viewport = availableSize; Debug(treeViewItem, "Desired height: " + Extent.Height); return Extent; }
// This is internal as an optimization for VirtualizingStackPanel (so it doesn't need to re-query InternalChildren repeatedly) internal static void RemoveInternalChildRange(UIElementCollection children, int index, int range) { children.RemoveRangeInternal(index, range); }
/// <summary> /// Measure the children /// </summary> /// <param name="availableSize">Size available</param> /// <returns>Size desired</returns> protected override Size MeasureOverride(Size availableSize) { if (ScrollOwner != null) { if (ScrollOwner.ScrollableWidth < HorizontalOffset) { SetHorizontalOffset(ScrollOwner.ScrollableWidth); } if (ScrollOwner.ScrollableHeight < VerticalOffset) { SetVerticalOffset(ScrollOwner.ScrollableHeight); } } // We need to access InternalChildren before the generator to work around a bug UIElementCollection children = InternalChildren; IItemContainerGenerator generator = ItemContainerGenerator; ItemsControl itemsControl = ItemsControl.GetItemsOwner(this); TreeViewExItem treeViewItem = itemsControl as TreeViewExItem; TreeViewEx treeView = itemsControl as TreeViewEx ?? treeViewItem.ParentTreeView; double currentY = 0; double maxWidth = 0; int firstVisibleItemIndex = 0; int lastVisibleItemIndex = 0; if (itemsControl.HasItems) { if (treeView.IsVirtualizing) { double bottomY = VerticalOffset + availableSize.Height; //add sizes of not visible items before visible ones to currentX for (int i = 0; i < itemsControl.Items.Count; i++) { // get height, maybe it is estimated double height = GetContainerHeightForItem(itemsControl, i); if (currentY + height >= VerticalOffset && currentY <= bottomY) { firstVisibleItemIndex = i; lastVisibleItemIndex = i; // we found the first visible item, lets realize it and all other visible items. while we // do so, we take care of counting i up GeneratorPosition startPos = generator.GeneratorPositionFromIndex(firstVisibleItemIndex); int itemGeneratorIndex = (startPos.Offset == 0) ? startPos.Index : startPos.Index + 1; using (generator.StartAt(startPos, GeneratorDirection.Forward, true)) { // create items until current y is bigger than bottomy => we reached the last visible item while (currentY <= bottomY && i < itemsControl.Items.Count) { // Get or create the child bool newlyRealized; TreeViewExItem child = generator.GenerateNext(out newlyRealized) as TreeViewExItem; if (newlyRealized) { // Figure out if we need to insert the child at the end or somewhere in the middle AddOrInsertItemToInternalChildren(itemGeneratorIndex, child); child.ParentTreeView = treeView; generator.PrepareItemContainer(child); } else { // The child has already been created, let's be sure it's in the right spot if (child != children[itemGeneratorIndex]) { throw new InvalidOperationException("Wrong child was generated"); } } child.Measure(new Size(double.MaxValue, double.MaxValue)); // now get the real height height = child.DesiredSize.Height; // add real height to cache cachedSizes.AddOrChange(i, height); // add real height to current position currentY += height; // save the maximum needed width maxWidth = Math.Max(maxWidth, child.DesiredSize.Width); lastVisibleItemIndex++; i++; itemGeneratorIndex++; //break realization if we reach the bottom of control if (currentY > bottomY) { break; } } } } else { currentY += height; } } // Note: this could be deferred to idle time for efficiency CleanUpItems(firstVisibleItemIndex, lastVisibleItemIndex); } else { GeneratorPosition startPos = generator.GeneratorPositionFromIndex(0); using (generator.StartAt(startPos, GeneratorDirection.Forward, true)) { for (int i = (startPos.Offset == 0) ? startPos.Index : startPos.Index + 1; i < itemsControl.Items.Count; i++) { // Get or create the child bool newlyRealized; TreeViewExItem child = generator.GenerateNext(out newlyRealized) as TreeViewExItem; if (newlyRealized) { // Figure out if we need to insert the child at the end or somewhere in the middle AddOrInsertItemToInternalChildren(i, child); child.ParentTreeView = treeView ?? treeViewItem.ParentTreeView; generator.PrepareItemContainer(child); } child.Measure(new Size(double.MaxValue, double.MaxValue)); // now get the real height double height = child.DesiredSize.Height; // add real height to current position currentY += height; // save the maximum needed width maxWidth = Math.Max(maxWidth, child.DesiredSize.Width); } } } } Extent = new Size(maxWidth, currentY); Viewport = availableSize; return(Extent); }