How to move an object in x y (diagnoal) direction in Silverlight C#
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++;
精彩评论