private static void SetLayoutStoryboardProperties(FrameworkElement control, FrameworkElement templateRoot, Storyboard layoutStoryboard, List <OriginalLayoutValueRecord> originalValueRecords) { foreach (var record in originalValueRecords) { ReplaceCachedLocalValueHelper(record.Element, record.Property, record.Value); } originalValueRecords.Clear(); foreach (var timeline in layoutStoryboard.Children) { var dependencyObject = (FrameworkElement)GetTimelineTarget(control, templateRoot, timeline); var property = LayoutPropertyFromTimeline(timeline, true); if (dependencyObject != null && property != null) { var valueFromTimeline = GetValueFromTimeline(timeline, out var flag); if (flag) { var item = new OriginalLayoutValueRecord { Element = dependencyObject, Property = property, Value = CacheLocalValueHelper(dependencyObject, property) }; originalValueRecords.Add(item); dependencyObject.SetValue(property, valueFromTimeline); } } } }
/// <summary> /// Go through the layout Storyboard and set all the properties by using SetValue to enable calling UpdateLayout without /// ticking the timeline, which would cause a render. /// All values that are overwritten will be stored in the collection of OriginalValueRecords so that they can be replaced later. /// </summary> /// <param name="control">The control whose state is changing</param> /// <param name="layoutStoryboard">The storyboard holding the layout properties</param> /// <param name="originalValueRecords">The store of original values</param> private static void SetLayoutStoryboardProperties(Control control, FrameworkElement templateRoot, Storyboard layoutStoryboard, List<OriginalLayoutValueRecord> originalValueRecords) { foreach (OriginalLayoutValueRecord record in originalValueRecords) { ReplaceCachedLocalValueHelper(record.Element, record.Property, record.Value); } originalValueRecords.Clear(); foreach (Timeline timeline in layoutStoryboard.Children) { FrameworkElement dependencyObject = (FrameworkElement)GetTimelineTarget(control, templateRoot, timeline); DependencyProperty property = LayoutPropertyFromTimeline(timeline, true); if ((dependencyObject != null) && (property != null)) { object to = null; bool flag = false; ObjectAnimationUsingKeyFrames frames = timeline as ObjectAnimationUsingKeyFrames; if (frames != null) { flag = true; to = frames.KeyFrames[0].Value; } else { DoubleAnimationUsingKeyFrames frames2 = timeline as DoubleAnimationUsingKeyFrames; if (frames2 != null) { flag = true; to = frames2.KeyFrames[0].Value; } else { DoubleAnimation animation = timeline as DoubleAnimation; if (animation != null) { flag = true; to = animation.To; } } } to = ConvertValueToExpectedType(property, to); if (((property == FrameworkElement.WidthProperty) || (property == FrameworkElement.HeightProperty)) && (((double)to) == -1.0)) { to = (double)1.0 / (double)0.0; } if (flag) { OriginalLayoutValueRecord item = new OriginalLayoutValueRecord { Element = dependencyObject, Property = property, Value = CacheLocalValueHelper(dependencyObject, property) }; originalValueRecords.Add(item); dependencyObject.SetValue(property, to); } } } }