Is CompositeTransform used only in silverlight?

后端 未结 2 2170
不思量自难忘°
不思量自难忘° 2021-02-20 14:39

CompositeTransform is only used for silverlight?. Is there anyway we can use that in WPF or any equivalent replacement?

相关标签:
2条回答
  • 2021-02-20 15:07

    Here is a much nicer solution if you are anal about code cleanliness:

    http://www.singulink.com/CodeIndex/post/getting-rid-of-ugly-transformgroup-blocks-in-wpf

    Its easy on the eyes and because it just returns a TransformGroup, you can still use the Blend designer to work with animating over the transform!

    <Rectangle Width="100" Height="100" Fill="LightGreen"
           RenderTransform="{data:CompositeTransform ScaleX=2.5, ScaleY=1, SkewX=-60, Rotation=145}"
           RenderTransformOrigin="0.5,0.5" />
    

    Implementation:

    public class CompositeTransformExtension : MarkupExtension
    {
        public double CenterX
        {
            get { return _scale.CenterX; }
            set
            {
                _scale.CenterX = value;
                _skew.CenterX = value;
                _rotate.CenterX = value;
    
            }
        }
    
        public double CenterY
        {
            get { return _scale.CenterY; }
            set
            {
                _scale.CenterY = value;
                _skew.CenterY = value;
                _rotate.CenterY = value;
            }
        }
    
        public double ScaleX
        {
            get { return _scale.ScaleX; }
            set { _scale.ScaleX = value; }
        }
    
        public double ScaleY
        {
            get { return _scale.ScaleY; }
            set { _scale.ScaleY = value; }
        }
    
        public double SkewX
        {
            get { return _skew.AngleX; }
            set { _skew.AngleX = value; }
        }
    
        public double SkewY
        {
            get { return _skew.AngleY; }
            set { _skew.AngleY = value; }
        }
    
        public double Rotation
        {
            get { return _rotate.Angle; }
            set { _rotate.Angle = value; }
        }
    
        public double TranslateX
        {
            get { return _translate.X; }
            set { _translate.X = value; }
        }
    
        public double TranslateY
        {
            get { return _translate.Y; }
            set { _translate.Y = value; }
        }
    
        private ScaleTransform _scale = new ScaleTransform();
        private SkewTransform _skew = new SkewTransform();
        private RotateTransform _rotate = new RotateTransform();
        private TranslateTransform _translate = new TranslateTransform();
    
        public CompositeTransformExtension()
        {
        }
    
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var group = new TransformGroup();
    
            group.Children.Add(_scale);
            group.Children.Add(_skew);
            group.Children.Add(_rotate);
            group.Children.Add(_translate);
    
            return group;
        }
    }
    
    0 讨论(0)
  • 2021-02-20 15:16

    There is no CompositeTransform in WPF however there is a TransformGroup. Hence an equivalent replacement is a TransformGroup containing ScaleTransform, SkewTransform, RotateTransform and TranslateTransform in that order.

    0 讨论(0)
提交回复
热议问题