0

I'm brand new to Silverlight and I'm in the deep end a little over my head so I'm probably missing something really obvious. I'm working on an image editor and I have a button on my main page that is supposed to rotate images or text on my canvas. The button however isn't calling my rotate method. EDIT: It is now.

Here's all the code I've written related to the button

MainPage.xaml

<Button Command="{Binding Path=Project.RotateCWElementCommand}"..../>

Project.cs -

#region properties

public ICommand RotateCWElementCommand { get; set; }

#endregion

#region methods
public Project(int siteID)
    {
        this.RotateCWElementCommand = new DelegateCommand(RotateCWElement, CanRotateCWElement);
    }

    private void RotateCWElement(object param)
    {
        FrameworkElement element = this.SelectedElement;
        RotateTransform cwRot = new RotateTransform();

        cwRot.Angle = 90;
        cwRot.CenterX = element.ActualWidth * 0.5;
        cwRot.CenterY = element.ActualHeight * 0.5;
        element.RenderTransform = cwRot;

    }

#end region

#region Command conditions

private bool CanRotateCWElement(object param)
    {
        return true;
    }

#endregion

The problem now is that it will only rotate once and some image quality also appears to be lost. The images move strangely when I click and drag them, and sometimes when I click the full image quality returns.

If anybody has any ideas about this it'd be great.

Steve
  • 29
  • 1
  • 8

2 Answers2

1

It sounds like the Button.DataContext does not contain a property called Project.RotateCWElementCommand

Verify that your Button's DataContext has a property called Project, and that Project has a property called RotateCWElementCommand

Rachel
  • 130,264
  • 66
  • 304
  • 490
  • Something simple and obvious it was it seems. Moved it into a stackpanel with a datacontext of project and it works. Thanks for the help. Any ideas on the single rotation? It still only works the first time. – Steve Jul 18 '12 at 15:49
  • @Steve The transform is separate from the actual object, so your regular object is being drawn, then it is being transformed 90 degrees. You'll probably need to save the current angle and adjust it by 90 degrees every time the Rotate command is run. – Rachel Jul 18 '12 at 16:06
0

The output window in Visual Studio can be very helpful for finding issues with your bindings in Silverlight and will help clarify if Rachel's suggestion is the problem.