Exemplo n.º 1
0
        /// <summary>
        /// Called when the SharedSizeScope for a given grid has changed.
        /// Unregisters the grid from it's current scope and finds a new one (if any)
        /// </summary>
        /// <remarks>
        /// This method, while not efficient, correctly handles nested scopes, with any order of scope changes.
        /// </remarks>
        internal void SharedScopeChanged()
        {
            _sharedSizeHost?.UnegisterGrid(this);

            _sharedSizeHost = null;
            var scope = this.GetVisualAncestors().OfType <Control>()
                        .FirstOrDefault(c => c.GetValue(IsSharedSizeScopeProperty));

            if (scope != null)
            {
                _sharedSizeHost = scope.GetValue(s_sharedSizeScopeHostProperty);
                _sharedSizeHost.RegisterGrid(this);
            }

            InvalidateMeasure();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Callback when a grid is attached to the visual tree. Finds the innermost SharedSizeScope and registers the grid
        /// in it.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The event arguments.</param>
        private void Grid_AttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e)
        {
            var scope =
                new Control[] { this }.Concat(this.GetVisualAncestors().OfType <Control>())
            .FirstOrDefault(c => c.GetValue(IsSharedSizeScopeProperty));

            if (_sharedSizeHost != null)
            {
                throw new AvaloniaInternalException("Shared size scope already present when attaching to visual tree!");
            }

            if (scope != null)
            {
                _sharedSizeHost = scope.GetValue(s_sharedSizeScopeHostProperty);
                _sharedSizeHost.RegisterGrid(this);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Callback when a grid is detached from the visual tree. Unregisters the grid from its SharedSizeScope if any.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The event arguments.</param>
 private void Grid_DetachedFromVisualTree(object sender, VisualTreeAttachmentEventArgs e)
 {
     _sharedSizeHost?.UnegisterGrid(this);
     _sharedSizeHost = null;
 }