/// <summary> /// Called from the Transitions Property of IFrameworkElement /// Attaches to the Loaded event /// </summary> /// <param name="element">Framework element to apply the transition to</param> internal void AttachToElement(IFrameworkElement element) { element.Loaded += OnElementLoaded; }
/// <summary> /// Called from the Transitions Property of IFrameworkElement /// </summary> /// <param name="element">Framework element to stop applying the transition to</param> internal void DetachFromElement(IFrameworkElement element) { element.Loaded -= OnElementLoaded; }
/// <summary> /// Finds a realised element in the control template /// </summary> /// <param name="e">The framework element instance</param> /// <param name="name">The name of the template part</param> public static DependencyObject GetTemplateChild(this IFrameworkElement e, string name) { return(e.FindName(name) as IFrameworkElement); }
private static IFrameworkElement ConvertFromStubToElement(this IFrameworkElement element, IFrameworkElement originalRootElement, string name) { var elementStub = element as ElementStub; if (elementStub != null) { elementStub.Materialize(); element = originalRootElement.FindName(name) as IFrameworkElement; } return(element); }
public static void SetVisualStateGroups(IFrameworkElement obj, IList <VisualStateGroup> value) { obj.SetValue(VisualStateGroupsProperty, value); }
/// <summary> /// Prepares a child for a measuring pass and sets up this child's sibling layout info and measures it when required /// </summary> /// <param name="child">The child to prepare for measure</param> /// <param name="availableSize">The available size in the panel</param> /// <param name="padding">The panel's padding</param> /// <param name="measureChild">The method to call when we need to measure the child</param> /// <param name="siblingLayoutInfos">The set of SiblingLayoutInfos from the child's siblings</param> /// <param name="updateCallerStack">The stack of all siblings that caused a remeasure of their dependencies, null at first pass</param> private void PrepareAndMeasureChild( IFrameworkElement child, Size availableSize, Thickness padding, Func <View, Size, Size> measureChild, Dictionary <IFrameworkElement, SiblingLayoutInfo> siblingLayoutInfos, List <IFrameworkElement> updateCallerStack = null) { bool needsCorrections = false; // Get the available area for the children, based on the currently laid out siblings and on the available size in the panel var areaForChild = GetAvailableAreaForChild(child, availableSize, siblingLayoutInfos, padding); var horizontalMargin = child.Margin.Left + child.Margin.Right; var verticalMargin = child.Margin.Top + child.Margin.Bottom; // If the area is smaller than the requiredSize, make sure it has enough space and raise a flag to correct errors afterward if ((!double.IsNaN(child.Width) && areaForChild.Width < (child.Width + horizontalMargin)) || areaForChild.Width < (child.MinWidth + horizontalMargin) || (!double.IsNaN(child.Height) && areaForChild.Height < (child.Height + verticalMargin)) || areaForChild.Height < (child.MinHeight + verticalMargin)) { needsCorrections = true; areaForChild.Width = Math.Max(Math.Max(double.IsNaN(child.Width) ? 0 : child.Width, child.MinWidth) + horizontalMargin, areaForChild.Width); areaForChild.Height = Math.Max(Math.Max(double.IsNaN(child.Height) ? 0 : child.Height, child.MinHeight) + verticalMargin, areaForChild.Height); } // Measure the child with the available size var childSize = measureChild(child as View, areaForChild.Size); // Get the area (including location) of the child based on the measured size and the layout information of other children in order var childArea = ExecuteOnSiblingLayoutInfoIfAvailable( child, siblingLayoutInfos, sli => ComputeChildArea(areaForChild, childSize, sli) ); var wasSet = ExecuteOnSiblingLayoutInfoIfAvailable(child, siblingLayoutInfos, sli => sli.IsAreaSet); // Update the Layout info with the newly found size var changed = ExecuteOnSiblingLayoutInfoIfAvailable(child, siblingLayoutInfos, sli => { if (sli.Area.Equals(childArea)) { return(false); } sli.Area = childArea; return(true); }); // If needed, correct the siblings based on the newlyfound forced size if ((needsCorrections && changed) || (wasSet && changed)) { var callerStack = updateCallerStack ?? new List <IFrameworkElement>(); callerStack.Add(child); UpdateSiblingsBasedOnSize( child, availableSize, padding, measureChild, siblingLayoutInfos, callerStack ); } }
public static bool ShouldFill(this IFrameworkElement fre, Orientation orientation) { return(orientation.IsHorizontal() ? fre.Width.IsNaN() && fre.HorizontalAlignment == HorizontalAlignment.Stretch : fre.Height.IsNaN() && fre.VerticalAlignment == VerticalAlignment.Stretch); }
/// <summary> /// Stores the elements Transformation - to be restored in the future /// </summary> private void PushRenderTransform(IFrameworkElement element) { _elementTransform = element.RenderTransform; }
internal static Size GetMinSize(this IFrameworkElement e) => new Size(e.MinWidth, e.MinHeight).NumberOrDefault(new Size(0, 0));
internal static Size GetMaxSize(this IFrameworkElement e) => new Size(e.MaxWidth, e.MaxHeight).NumberOrDefault(new Size(PositiveInfinity, PositiveInfinity));
internal void GoToState(IFrameworkElement element, VisualState state, VisualState originalState, bool useTransitions, Action onStateChanged) { if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().DebugFormat("Go to state [{0}/{1}] on [{2}]", Name, state?.Name, element); } var transition = FindTransition(originalState?.Name, state?.Name); EventHandler <object> onComplete = null; onComplete = (s, a) => { onStateChanged(); if (state?.Storyboard == null) { return; } state.Storyboard.Completed -= onComplete; }; EventHandler <object> onTransitionComplete = null; onTransitionComplete = (s, a) => { if (transition?.Storyboard != null && useTransitions) { transition.Storyboard.Completed -= onTransitionComplete; if (state?.Storyboard != null) { transition.Storyboard.TurnOverAnimationsTo(state.Storyboard); } } //Starts Storyboard Animation if (state?.Storyboard == null) { onComplete(this, null); } else if (state != null) { state.Storyboard.Completed += onComplete; state.Storyboard.Begin(); } }; //Stops Previous Storyboard Animation if (originalState != null) { if (originalState.Storyboard != null) { if (transition?.Storyboard != null) { originalState.Storyboard.TurnOverAnimationsTo(transition.Storyboard); } else if (state?.Storyboard != null) { originalState.Storyboard.TurnOverAnimationsTo(state.Storyboard); } else { originalState.Storyboard.Stop(); } } foreach (var setter in this.CurrentState.Setters.OfType <Setter>()) { setter.ClearValue(); } } this.CurrentState = state; if (this.CurrentState != null) { foreach (var setter in this.CurrentState.Setters.OfType <Setter>()) { setter.ApplyValue(DependencyPropertyValuePrecedences.Animations, element); } } if (transition?.Storyboard == null || !useTransitions) { onTransitionComplete(this, null); } else { transition.Storyboard.Completed += onTransitionComplete; transition.Storyboard.Begin(); } }
protected virtual void OnChildAdded(IFrameworkElement element) { UpdateTransitions(element); }
public Sibling(IFrameworkElement element) { Element = element; Dependencies = new List <SiblingDependency>(); }
/// <summary> /// Called from the ChildTransistions Property of a Panel /// Attaches to the Completed event - Keeps the starting RenderTansform on the FrameworkElement and restores it; /// </summary> /// <param name="storyboard">The Panel may run several Transitions on the same Storyboard</param> /// <param name="element">FrameworkElement to Animate</param> /// <param name="beginTime">Used for Staggering (default Timespan.Zero)</param> /// <param name="xOffset">Used to determine the x axis renderTransform translation. The previous position of the IFrameworkElement in a List (Only used in reposition)</param> /// <param name="yOffset">Used to determine the y axis renderTransform translation. The previous position of the IFrameworkElement in a List (Only used in reposition)</param> internal virtual void AttachToStoryboardAnimation(Storyboard storyboard, IFrameworkElement element, TimeSpan beginTime, int xOffset = 0, int yOffset = 0) { PushRenderTransform(element); storyboard.Completed += (s, e) => PopRenderTransform(element); }
private async Task GenerateBitmap(CancellationToken ct, string folderName, string fileName, IFrameworkElement content) { Directory.CreateDirectory(folderName); TakeScreenShot(Path.Combine(folderName, fileName)); }
/// <summary> /// Restores the Stored Transformation /// </summary> private void PopRenderTransform(IFrameworkElement element) { (element).RenderTransform = _elementTransform; }
public FrameworkElementLayouter(IFrameworkElement element, MeasureOverrideHandler measureOverrideHandler, ArrangeOverrideHandler arrangeOverrigeHandler) : base(element) { _measureOverrideHandler = measureOverrideHandler; _arrangeOverrideHandler = arrangeOverrigeHandler; }
public static IList <VisualStateGroup> GetVisualStateGroups(IFrameworkElement obj) => (IList <VisualStateGroup>)obj.GetValue(VisualStateGroupsProperty);
public Layouter(IFrameworkElement element) { _element = element; }
internal static void SetVisualStateManager(IFrameworkElement obj, VisualStateManager value) { obj.SetValue(VisualStateManagerProperty, value); }
/// <summary> /// Gets the Sibling structure associated to a particular FrameworkElement /// </summary> internal Sibling GetSibling(IFrameworkElement element) { return(_nodes.FirstOrDefault(s => s.Element.Equals(element))); }