/// <summary> /// Provides the behavior for the "Measure" pass of layout. /// </summary> /// <param name="availableSize">The available size that this element can give to child elements.</param> /// <returns>The size that this element determines it needs during layout, based on its calculations of child element sizes.</returns> protected override Size MeasureOverride(Size availableSize) { FrameworkElement child = Child; if ((null == _transformRoot) || (null == child)) { // No content, no size return(Size.Empty); } DiagnosticWriteLine("MeasureOverride < " + availableSize); Size measureSize; if (_childActualSize == Size.Empty) { // Determine the largest size after the transformation measureSize = ComputeLargestTransformedSize(availableSize); } else { // Previous measure/arrange pass determined that Child.DesiredSize was larger than believed DiagnosticWriteLine(" Using _childActualSize"); measureSize = _childActualSize; } // Perform a mesaure on the _transformRoot (containing Child) DiagnosticWriteLine(" _transformRoot.Measure < " + measureSize); _transformRoot.Measure(measureSize); DiagnosticWriteLine(" _transformRoot.DesiredSize = " + _transformRoot.DesiredSize); // WPF equivalent of _childActualSize technique (much simpler, but doesn't work on Silverlight 2) // // If the child is going to render larger than the available size, re-measure according to that size // child.Arrange(new Rect()); // if (child.RenderSize != child.DesiredSize) // { // _transformRoot.Measure(child.RenderSize); // } // Transform DesiredSize to find its width/height Rect transformedDesiredRect = RectTransform(new Rect(0, 0, _transformRoot.DesiredSize.Width, _transformRoot.DesiredSize.Height), _transformation); Size transformedDesiredSize = new Size(transformedDesiredRect.Width, transformedDesiredRect.Height); // Return result to allocate enough space for the transformation DiagnosticWriteLine("MeasureOverride > " + transformedDesiredSize); return(transformedDesiredSize); }
/// <summary> /// Gets the width of the panel desired. /// </summary> /// <param name="panel">The panel.</param> /// <returns>Returns the desired width of the child elements.</returns> private static double GetPanelDesiredWidth(Panel panel) { double desiredWidth = 0; desiredWidth = panel.DesiredSize.Width; if (desiredWidth == 0) { panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); desiredWidth = panel.DesiredSize.Width; } return desiredWidth; }
/// <summary> /// Apply animation for point chart /// </summary> /// <param name="pointGrid">Point chart grid</param> /// <param name="storyboard">Stroyboard</param> /// <param name="width">Width of the chart canvas</param> /// <param name="height">Height of the chart canvas</param> /// <returns>Storyboard</returns> private static Storyboard ApplyPointChartAnimation(DataSeries currentDataSeries, Panel pointGrid, Storyboard storyboard, Double width, Double height) { #if WPF if (storyboard != null && storyboard.GetValue(System.Windows.Media.Animation.Storyboard.TargetProperty) != null) storyboard.Stop(); #else if (storyboard != null) storyboard.Stop(); #endif TransformGroup group = new TransformGroup(); ScaleTransform scaleTransform = new ScaleTransform() { ScaleX = 0, ScaleY = 0, CenterX = 0.5, CenterY = 0.5 }; TranslateTransform translateTransform = new TranslateTransform() { X = 0, Y = 0 }; group.Children.Add(scaleTransform); group.Children.Add(translateTransform); pointGrid.RenderTransform = group; Random rand = new Random((Int32)DateTime.Now.Ticks); double begin = rand.NextDouble(); pointGrid.Measure(new Size(Double.MaxValue, Double.MaxValue)); DoubleCollection times = Graphics.GenerateDoubleCollection(0, 0.5, 0.75, 1); DoubleCollection scaleValues = Graphics.GenerateDoubleCollection(0, 1, 0.5, 1); DoubleCollection translateXValues = Graphics.GenerateDoubleCollection(pointGrid.DesiredSize.Width / 2, 0, pointGrid.DesiredSize.Width / 4, 0); DoubleCollection translateYValues = Graphics.GenerateDoubleCollection(pointGrid.DesiredSize.Height / 2, 0, pointGrid.DesiredSize.Height / 4, 0); List<KeySpline> splines1 = AnimationHelper.GenerateKeySplineList(new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1)); List<KeySpline> splines2 = AnimationHelper.GenerateKeySplineList(new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1)); List<KeySpline> splines3 = AnimationHelper.GenerateKeySplineList(new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1)); List<KeySpline> splines4 = AnimationHelper.GenerateKeySplineList(new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1)); DoubleAnimationUsingKeyFrames xScaleAnimation = AnimationHelper.CreateDoubleAnimation(currentDataSeries, scaleTransform, "(ScaleTransform.ScaleX)", begin + 0.5, times, scaleValues, splines1); DoubleAnimationUsingKeyFrames yScaleAnimation = AnimationHelper.CreateDoubleAnimation(currentDataSeries, scaleTransform, "(ScaleTransform.ScaleY)", begin + 0.5, times, scaleValues, splines2); DoubleAnimationUsingKeyFrames xTranslateAnimation = AnimationHelper.CreateDoubleAnimation(currentDataSeries, translateTransform, "(TranslateTransform.X)", begin + 0.5, times, translateXValues, splines3); DoubleAnimationUsingKeyFrames yTranslateAnimation = AnimationHelper.CreateDoubleAnimation(currentDataSeries, translateTransform, "(TranslateTransform.Y)", begin + 0.5, times, translateYValues, splines4); storyboard.Children.Add(xScaleAnimation); storyboard.Children.Add(yScaleAnimation); storyboard.Children.Add(xTranslateAnimation); storyboard.Children.Add(yTranslateAnimation); return storyboard; }