Skip to main content

Microsoft Silverlight

Answered Question Cannot use transforms dynamically with JavascriptRSS Feed

(0)

Nevetha
Nevetha

Member

Member

0 points

3 Posts

Cannot use transforms dynamically with Javascript

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
mrjvdveen

Participant

Participant

1937 points

366 Posts

Re: Cannot use transforms dynamically with Javascript

 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.

-------------
Please mark a post as answer if it answers your question.
Visit my blog: http://jvdveen.blogspot.com

daf555
daf555

Member

Member

60 points

11 Posts

Answered Question

Re: Re: Cannot use transforms dynamically with Javascript

It is the "Name" attribute of the TranslateTransform. Simply delete this attribute and you will see it will work.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities