我是Silverlight的全新人物,而且我的頭腦微微低落,所以我可能錯過了一些非常明顯的東西。我正在研究一個圖像編輯器,並且我的主頁上有一個按鈕,用於在畫布上旋轉圖像或文本。但按鈕不是調用我的旋轉方法。編輯:現在是。主頁上的Silverlight按鈕,鏈接到命令,從不調用方法
這裏的一切我已經寫了相關的按鈕
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
現在的問題是,它只能旋轉一次和一些圖像質量也似乎丟失。當我點擊並拖動它們時,圖像會奇怪地移動,有時當我點擊完整圖像質量返回時。
如果有人對此有任何想法,它會很棒。
看起來很簡單明顯。將它移動到一個帶有項目的datacontext的堆棧面板中,並且它可以工作。謝謝您的幫助。任何關於單輪轉的想法?它仍然只是第一次。 – Steve 2012-07-18 15:49:36
@Steve轉換與實際對象是分開的,所以您的常規對象正在被繪製,然後它被轉換90度。每次運行Rotate命令時,您可能都需要保存當前角度並將其調整90度。 – Rachel 2012-07-18 16:06:34