locked
Scaling a programmatically created canvas RRS feed

  • Question

  • How can I scale a programmatically created canvas?  I know if I create a canvas in XAML, then I can add a RenderTransform group with a ScaleTransform.  Then, I can manipulate the ScaleTransform from code.  But, if I create the Canvas from code, how can I add the RenderTransform group with a ScaleTransform?

    objBackGroundLayer = NewCanvas
    objBackGroundLayer.Name = "BGLayer" & strSide & intLayer.ToString
    objBackGroundLayer.Background = clrBG
    Canvas.SetLeft(objBackGroundLayer,0)
    Canvas.SetTop(objBackGroundLayer,60 + intLayer * 20)
    objBackGroundLayer.Width = intLayerWidth
    objBackGroundLayer.Height = intLayerHeight
    AddPropsToBackGroundLayer(objBackGroundLayer)

    In the code, I create the new canvas, set its coordinates, and add some user controls to it.

    I want to be able to scale the canvas along with the props (user controls) that were added to its Children collection.

    Thanks,

    Mike


    Monday, May 4, 2009 5:10 PM

Answers

  • You can apply a transform like:

     

     ScaleTransform scale = new ScaleTransform();
      
    scale.ScaleX = x_doubleValue;
    scale.ScaleY = y_doubleValue;

     objBackGroundLayer.RenderTransform=scale;

    where in the x_doubleValue and y_doubleValue you can put your desired x,y transform double values.

    Please mark as answered if it helped.

    Monday, May 4, 2009 6:52 PM