Skip to main content
Home Forums Silverlight Programming Programming with JavaScript Cannot use transforms dynamically with Javascript
2 replies. Latest Post by daf555 on June 10, 2009.
(0)
Nevetha
Member
0 points
3 Posts
06-09-2009 5:42 AM |
Hi All,
This is a piece of code that I have in Javascript that adds transforms dynamically
function createGeometry(sender, mouseArgs) { if(currentSelection == "Rectangle") { var plugin = sender.getHost(); var endX = mouseArgs.getPosition(null).x; var endY = mouseArgs.getPosition(null).y; var rect; var xamlFragment ='<Rectangle Width="60" Height="60" Fill="Blue" MouseLeftButtonDown="OnMouseLeftButtonDown" MouseLeftButtonUp="OnMouseLeftButtonUp" MouseMove="OnMouseMove">'; xamlFragment += '<Rectangle.RenderTransform> <TranslateTransform Name="myTranslateTransform"/> </Rectangle.RenderTransform>'; xamlFragment +='</Rectangle>'; rect = plugin.content.createFromXaml(xamlFragment, false); rect["Canvas.Left"] = endX - sender["Canvas.Left"]; rect["Canvas.Top"] = endY - sender["Canvas.Top"]; sender.children.add(rect); } }
First time the Rectangle Object is created and the transform(which is written as separate function) works fine. But the next time am not able to create the rectangle object.
Can anyone identify the issue with my code.
Thanks & Cheers
N
mrjvdveen
Participant
1937 points
366 Posts
06-10-2009 2:30 AM |
My first guess would be that the myTranslateTransform, which is a child of the Rectangle, already exists and can't be added to the visualization tree. In turn it's parent, the Rectangle, can't be added either.
HTH.
daf555
60 points
11 Posts
06-10-2009 12:36 PM |
It is the "Name" attribute of the TranslateTransform. Simply delete this attribute and you will see it will work.