tags:

views:

17

answers:

1

Hey there, I have:
this.onePX.To = 64;

With the XAML:

<Rectangle Width="32" Height="32" Fill="Black" x:Name="onePX" Grid.Column="0" Grid.Row="0">
                <Rectangle.RenderTransform>
                    <TranslateTransform />
                </Rectangle.RenderTransform>
            </Rectangle>

but for some reason, it returns with:
System.Windows.Shapes.Rectangle does not contain a definition for "To" and no extension method "To"...

Any idea why this could be happening, I tried to Google it, but searching for ".To" doesn't exactly yield accurate results ^.^

+1  A: 

A Silverlight Rectangle does not have a "To" member (or method etc), so the compiler is quite right.

What are you actually trying to do the the Rectangle? That might result in better answers.

Edit 2

Ok, if you want to move a rectangle (on a pixel basis I assume as you said to an X,Y coordinate) you 1st need to parent it under a Canvas. Only a canvas renders children on a pixel basis.

Secondly to actually move a child of a Canvas, you need to set the attached properties Canvas.LeftProperty and Canvas.TopProperty.

You can either do this using the static methods Canvas.SetLeft(onePX, newValue) and Canvas.SetTop(onePx, newValue) (which take the child object and new values as parameters), or you can use the other SetValue syntax which looks like this.onePX.SetValue(Canvas.LeftProperty, newValue) and this.onePx.SetValue(Canvas.LeftProperty, newValue) etc.

The first static-method syntax is usually shorter and easier on the eyes :)

Hope this helps.

Enough already
Hey, cheers for the quick response. I'm trying to move the Rectangle to a specific X,Y co-ordinate.
Neurofluxation
Worked lovely, thank you v. much!
Neurofluxation