111,129
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Image Name="image1" Source="/WpfApplication1;component/bin/Debug/1.jpg"
MouseDown="image1_MouseDown"
MouseMove="image1_MouseMove"
MouseUp="image1_MouseUp">
</Image>
</Grid>
</Window>
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private Boolean m_IsMouseDown;
double startAngle;
private void image1_MouseDown(object sender, MouseButtonEventArgs e)
{
m_IsMouseDown = true;
Point center = new Point(image1.ActualWidth / 2, image1.ActualHeight / 2);
Point mouseLoc = e.GetPosition(image1);
startAngle = Math.Atan2(mouseLoc.Y - center.Y, mouseLoc.X - center.Y);
}
private void image1_MouseMove(object sender, MouseEventArgs e)
{
if (!m_IsMouseDown)
return;
Point center = new Point(image1.ActualWidth / 2, image1.ActualHeight / 2);
Point mouseLoc = e.GetPosition(image1);
double endAngle = Math.Atan2(mouseLoc.Y - center.Y, mouseLoc.X - center.Y);
double d = endAngle - startAngle;
double degree = d / Math.PI * 180;
image1.LayoutTransform = new RotateTransform(degree);
}
private void image1_MouseUp(object sender, MouseButtonEventArgs e)
{
m_IsMouseDown = false;
}
}