private void OnSizeChanged(object sender, SizeChangedEventArgs e) { using (_settingsChangeScope.Enter()) { SaveWindowDimensions(); } }
public void StateScopeEntranceTest() { var scope = new StateScope(); Assert.AreEqual(false, scope.IsWithin); using (scope.Enter()) { Assert.AreEqual(true, scope.IsWithin); using (scope.Enter()) { Assert.AreEqual(true, scope.IsWithin); } Assert.AreEqual(true, scope.IsWithin); } Assert.AreEqual(false, scope.IsWithin); }
public void StateScopeEntranceTriggersCallback() { var eventsRaised = 0; Action callback = () => eventsRaised++; var scope = new StateScope(callback); Assert.AreEqual(0, eventsRaised); using (scope.Enter()) { // Went from false to true - so it should have raised Assert.AreEqual(1, eventsRaised); using (scope.Enter()) { // Already in - no raise Assert.AreEqual(1, eventsRaised); } // Still in - no raise Assert.AreEqual(1, eventsRaised); } // Left - raise Assert.AreEqual(2, eventsRaised); }
/// <summary> /// Measures the children of a <see cref="T:System.Windows.Controls.Grid"/> in anticipation of arranging them during the <see cref="FrameworkElement.ArrangeOverride"/> pass. /// </summary> /// <param name="constraint">Indicates an upper limit size that should not be exceeded.</param> /// <returns> /// <see cref="Size"/> that represents the required size to arrange child content. /// </returns> protected override Size MeasureOverride(Size constraint) { using (_layoutScope.Enter()) { var isVertical = Orientation == Orientation.Vertical; if (_shouldReindex || (IsAutoIndexing && ((isVertical && _rowOrColumnCount != ColumnDefinitions.Count) || (!isVertical && _rowOrColumnCount != RowDefinitions.Count)))) { _shouldReindex = false; if (IsAutoIndexing) { _rowOrColumnCount = (isVertical) ? ColumnDefinitions.Count : RowDefinitions.Count; if (_rowOrColumnCount == 0) { _rowOrColumnCount = 1; } var cellCount = 0; var currentRow = 0; var currentColumn = 0; var reservedPositions = new HashSet <ReservedPosition>(); foreach (UIElement child in Children) { ChildLayoutInfo layoutInfo; if (!_childData.TryGetValue(child, out layoutInfo)) { layoutInfo = new ChildLayoutInfo { OriginalColumn = Undefined, OriginalRow = Undefined }; if (!child.HasDefaultValue(ColumnProperty)) { layoutInfo.OriginalColumn = GetColumn(child); if ((Orientation == Orientation.Vertical) && (layoutInfo.OriginalColumn >= ColumnDefinitions.Count)) { layoutInfo.OriginalColumn = ColumnDefinitions.Count - 1; } } if (!child.HasDefaultValue(RowProperty)) { layoutInfo.OriginalRow = GetRow(child); if ((Orientation == Orientation.Horizontal) && (layoutInfo.OriginalRow >= RowDefinitions.Count)) { layoutInfo.OriginalRow = RowDefinitions.Count - 1; } } _childData[child] = layoutInfo; } if (layoutInfo.OriginalColumn != Undefined) { if (layoutInfo.OriginalRow != Undefined) { layoutInfo.ActualColumn = layoutInfo.OriginalColumn; layoutInfo.ActualRow = layoutInfo.OriginalRow; reservedPositions.Add( new ReservedPosition( layoutInfo.ActualColumn, layoutInfo.ActualRow)); } else if (isVertical) { while ((layoutInfo.OriginalColumn != currentColumn) || reservedPositions.Contains(new ReservedPosition(currentRow, currentColumn))) { ++cellCount; if (++currentColumn >= _rowOrColumnCount) { currentColumn = 0; ++currentRow; } } layoutInfo.ActualRow = currentRow; layoutInfo.ActualColumn = currentColumn; } } else if (layoutInfo.OriginalRow != Undefined) { if (!isVertical) { while ((layoutInfo.OriginalRow != currentRow) || reservedPositions.Contains(new ReservedPosition(currentRow, currentColumn))) { ++cellCount; if (++currentRow >= _rowOrColumnCount) { currentRow = 0; ++currentColumn; } } layoutInfo.ActualRow = currentRow; layoutInfo.ActualColumn = currentColumn; } } else { while (reservedPositions.Contains(new ReservedPosition(currentRow, currentColumn))) { ++cellCount; if (isVertical) { if (++currentColumn >= _rowOrColumnCount) { currentColumn = 0; ++currentRow; } } else { if (++currentRow >= _rowOrColumnCount) { currentRow = 0; ++currentColumn; } } } layoutInfo.ActualColumn = currentColumn; layoutInfo.ActualRow = currentRow; } ++cellCount; SetRow(child, layoutInfo.ActualRow); SetColumn(child, layoutInfo.ActualColumn); var childRowSpan = GetRowSpan(child); var childColumnSpan = GetColumnSpan(child); if (isVertical) { if (!child.HasDefaultValue(ColumnSpanProperty)) { if ((currentColumn + childColumnSpan) >= _rowOrColumnCount) { childColumnSpan -= ((currentColumn + childColumnSpan) - _rowOrColumnCount - 1); } cellCount += childRowSpan * childColumnSpan; for (var i = 0; i < (childColumnSpan - 1); i++) { reservedPositions.Add(new ReservedPosition(currentRow, currentColumn + i)); } } if (!child.HasDefaultValue(RowSpanProperty)) { cellCount += childRowSpan * childColumnSpan; for (var i = 0; i < (childRowSpan - 1); i++) { reservedPositions.Add(new ReservedPosition(currentRow + i, currentColumn)); } } else if (++currentColumn >= _rowOrColumnCount) { currentColumn = 0; ++currentRow; } } else { if (!child.HasDefaultValue(RowSpanProperty)) { if ((currentColumn + childRowSpan) >= _rowOrColumnCount) { childRowSpan -= ((currentColumn + childRowSpan) - _rowOrColumnCount - 1); } cellCount += childRowSpan * childColumnSpan; for (var i = 0; i < (childRowSpan - 1); i++) { reservedPositions.Add(new ReservedPosition(currentRow + i, currentColumn)); } } if (!child.HasDefaultValue(ColumnSpanProperty)) { cellCount += childRowSpan * childColumnSpan; for (var i = 0; i < (childColumnSpan - 1); i++) { reservedPositions.Add(new ReservedPosition(currentRow, currentColumn + i)); } } else if (++currentRow >= _rowOrColumnCount) { currentRow = 0; ++currentColumn; } } } // Update the number of rows/columns if (isVertical) { int newRowCount = ((cellCount - 1) / _rowOrColumnCount + 1); while (RowDefinitions.Count < newRowCount) { RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); } if (RowDefinitions.Count > newRowCount) { RowDefinitions.RemoveRange(newRowCount, RowDefinitions.Count - newRowCount); } } else // horizontal { int newColumnCount = ((cellCount - 1) / _rowOrColumnCount + 1); while (ColumnDefinitions.Count < newColumnCount) { ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); } if (ColumnDefinitions.Count > newColumnCount) { ColumnDefinitions.RemoveRange(newColumnCount, ColumnDefinitions.Count - newColumnCount); } } } // Set margin and alignment foreach (UIElement child in Children) { if (ChildMargin != null) { child.SetIfDefault(MarginProperty, ChildMargin.Value); } if (ChildHorizontalAlignment != null) { child.SetIfDefault(HorizontalAlignmentProperty, ChildHorizontalAlignment.Value); } if (ChildVerticalAlignment != null) { child.SetIfDefault(VerticalAlignmentProperty, ChildVerticalAlignment.Value); } } } return(base.MeasureOverride(constraint)); } }
public IDisposable SuppressDraw() { return(_suppressDrawScope.Enter()); }
internal IDisposable BeginDeviceChange() { return(_deviceTransitionScope.Enter()); }
public IDisposable Run() { return(_runScope.Enter()); }
public IDisposable EnterUpdateScope() { return(_updateScope.Enter()); }