How do I use CompositeTransform in C #?

How can I code this XAML code in C #?

<TextBlock Text="..." RenderTransformOrigin="0.5,0.5">
                        <CompositeTransform TranslateY="-25"/>


I tried this way:

private TextBlock dots;
dots = new TextBlock();
dots.Text = "...";
dots.RenderTransformOrigin = new Point(0.5, 0.5); 
(dots.RenderTransform as CompositeTransform).TranslateY = 20;


But I am getting System.NullReferenceException . I also tried this way:

var ct = (CompositeTransform)dots.RenderTransform;
            ct.TranslateY = 20;


But I am getting System.InvalidCastException ( Can not cast object of type "System.Windows.Media.MatrixTransform" to input "System.Windows.Media.CompositeTransform".)

Thanks in advance!


source to share

1 answer

If you are creating a new control from scratch, this property RenderTransform

will be Identity MatrixTransform

, so you cannot target it to CompositeTransform

. You should do it like this:

dots.RenderTransform = new CompositeTransform { TranslateY = 20 };




All Articles