请根据我的要求找到附加的图像。当拖动弧(边框)时,弧和滚轮通过鼠标位置旋转。你能帮我吗?如果在按钮中旋转弧和轮,请单击它工作。但我想在拖动边框(弧)中旋转它。我被计算卡住了。
XAML:
<Grid HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal" x:Name="mainStackPanel" RenderTransformOrigin="0.5,0.5">
<Grid>
<Border BorderThickness="10" BorderBrush="Blue" MouseMove="Border_MouseMove" MouseLeftButtonDown="Border_MouseLeftButtonDown"
MouseLeftButtonUp="Border_MouseLeftButtonUp" Width="10" Height="90" />
</Grid>
<Grid x:Name="rotateGrid" Margin="20 0 0 0" RenderTransformOrigin="0.5,0.5">
<Ellipse Height="250" Width="250" Stroke="Red" StrokeThickness="20"/>
<Border BorderThickness="10" BorderBrush="Red" Height="15" Width="250"
HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
<Border BorderThickness="10" BorderBrush="Red" Width="15" Height="250"
HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
<Border BorderThickness="10" BorderBrush="Red" Width="15" Height="246" RenderTransformOrigin="0.5,0.5"
HorizontalAlignment="Center" VerticalAlignment="Stretch">
<Border.RenderTransform>
<RotateTransform Angle="45"/>
</Border.RenderTransform>
</Border>
<Border BorderThickness="10" BorderBrush="Red" Width="15" Height="246" RenderTransformOrigin="0.5,0.5"
HorizontalAlignment="Center" VerticalAlignment="Stretch">
<Border.RenderTransform>
<RotateTransform Angle="135"/>
</Border.RenderTransform>
</Border>
</Grid>
<Grid Margin="20 0 0 0">
<Border BorderThickness="10" BorderBrush="Blue" Width="10" Height="90" />
</Grid>
</StackPanel>
Code Behind:
RotateTransform trans = new RotateTransform();
double angle = 30;
Point oldPoint;
Point newPoint;
bool dragStarted = false;
private void Button_Click(object sender, RoutedEventArgs e)
{
trans.Angle = angle;
mainStackPanel.RenderTransform = trans;
if (angle >= 360)
angle = 0;
angle += 30;
}
private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
dragStarted = true;
oldPoint = e.GetPosition(this);
Mouse.Capture(sender as IInputElement);
}
private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Mouse.Capture(null);
oldPoint = new Point(0, 0);
newPoint = new Point(0, 0);
dragStarted = false;
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
Mouse.Capture(null);
oldPoint = new Point(0, 0);
newPoint = new Point(0, 0);
dragStarted = false;
base.OnMouseLeftButtonUp(e);
}
private void Border_MouseMove(object sender, MouseEventArgs e)
{
if (dragStarted)
{
newPoint = e.GetPosition(this);
if (oldPoint.Y != newPoint.Y)
{
if (oldPoint.Y > newPoint.Y)
trans.Angle = (oldPoint.Y - newPoint.Y);
else
trans.Angle += (newPoint.Y - oldPoint.Y);
mainStackPanel.RenderTransform = trans;
}
}
}