开发者

How to move an object in x y (diagnoal) direction in Silverlight C#

开发者 https://www.devze.com 2023-01-29 09:41 出处:网络
i want to move an canvas in diagonal direction when i tried to TranslateTransform in xaml it works but from code behind it is not working

i want to move an canvas in diagonal direction when i tried to TranslateTransform in xaml it works but from code behind it is not working

<Canvas.RenderTransform>
   <TranslateTransform X="1" Y ="1"/>
</Canvas.RenderTransform>

code:-

public void AnimateTo(Canvas c)
{
        // update the value
     开发者_Python百科   TranslateTransform translate = c.RenderTransform as TranslateTransform;
        translate.Y = --x;
        translate.X = --y;
}

Can some one help me


You cannot access the RenderTransform this way in code. Set a name to your TranslateTransform tag like this :

<Canvas.RenderTransform>
    <TranslateTransform x:Name="myCanvasTranslate" X="1" Y ="1"/>
</Canvas.RenderTransform>

then in code, use :

myCanvasTranslate.X++;

myCanvasTranslate.Y++;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号