public static Rect GetContentBoundingBox(this FrameworkElement element, Visual relativeTo) { element.AssertParameterNotNull(nameof(element)); relativeTo.AssertNotNull(nameof(relativeTo)); return(element.GetVisualContent().GetBoundingBox(relativeTo)); }
public static FrameworkElement GetVisualContent(this FrameworkElement element) { element.AssertParameterNotNull(nameof(element)); if (element is ICustomContentOwner customContentOwner) { return(customContentOwner.ContentElement); } return(element); }
private void AssertSelectionBoxProperties(FrameworkElement owner, SelectionBox selectionBox) { owner.AssertParameterNotNull(nameof(owner)); selectionBox.AssertParameterNotNull(nameof(selectionBox)); selectionBox.TargetType.AssertParameterNotNull(nameof(SelectionBox.TargetType)); selectionBox.TargetSelectionProperty.AssertParameterNotNull(nameof(SelectionBox.TargetSelectionProperty)); selectionBox.VisualTraverser.AssertParameterNotNull(nameof(SelectionBox.VisualTraverser)); if (!typeof(FrameworkElement).IsAssignableFrom(selectionBox.TargetType)) { throw new Exception($"Error : Only FrameworkElements can be targeted by a SelectionBox. The given target type {SelectionBox.TargetType.Name} " + $"does not extend FrameworkElement."); } if (selectionBox.TargetSelectionProperty == null || selectionBox.TargetSelectionProperty.ReadOnly || selectionBox.TargetSelectionProperty.PropertyType != typeof(bool)) { throw new Exception($"Error : The target selection property represents the property if, which set, selects the UIElement of the item found inside the SelectionBox. " + $"This cannot be null or readOnly and it's TargetType must be bool."); } }
/// <summary> /// Ensures the specified FrameworkElement is unloaded before executing the specified action. <para/> /// If the element is unloaded, the action will be executed right away. Otherwise, the execution will be delayed until the element is unloaded. /// </summary> /// <param name="frameworkElement"></param> /// <param name="action"></param> public static void EnsureUnloaded(this FrameworkElement frameworkElement, Action action) { frameworkElement.AssertParameterNotNull(nameof(frameworkElement)); action.AssertParameterNotNull(nameof(action)); if (!frameworkElement.IsLoaded) { action(); } else { void unloadHandler(object sender, RoutedEventArgs e) { action(); frameworkElement.Unloaded -= unloadHandler; } frameworkElement.Unloaded += unloadHandler; } }