我不想使用内置系统进行旋转,使用两根手指,因为我必须用一个点旋转它。
我正在尝试在画布中旋转矩形。但由于某种原因,矩形震动,额外转弯。任何人都知道什么是错的?
有谁知道我怎么能做像wpf Translate这样的事情。
指向myPoint = control.TranslatePoint(点,父)?
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Canvas x:Name="myCanvas" MinHeight="400" MinWidth="400" >
<Rectangle x:Name="Spinner" Fill="LightGray" Canvas.Left="100" Canvas.Top="100" Height="200" Width="200"
ManipulationMode="All"
ManipulationDelta="Spinner_ManipulationDelta" >
<Rectangle.RenderTransform>
<CompositeTransform x:Name="myTransform" CenterX="100" CenterY="100" Rotation="0" />
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="20" >
<TextBlock Text="Speed (px per Millisecond): " />
<TextBlock x:Name="SpeedX" ManipulationMode="None" Text="0" />
<TextBlock Text=", " />
<TextBlock x:Name="SpeedY" ManipulationMode="None" Text="0"/>
<TextBlock Text="Point: " />
<TextBlock x:Name="PointX" ManipulationMode="None" Text="0" />
<TextBlock Text=", " />
<TextBlock x:Name="PointY" ManipulationMode="None" Text="0"/>
</StackPanel>
</Grid>
</Page>
背后的代码非常简单
private void Spinner_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
Point touch = e.Position; // Really want this point to be relative to the canvas
Point center = new Point(100, 100); // Really want the point relative to the canvas
double x = touch.X - center.Y;
double y = center.Y - touch.Y; // Tried this reversed.. No difference
double radians = Math.Atan2(y, x);
myTransform.Rotation += radians;
// show the mouse position in the UI
this.PointX.Text = touch.X.ToString();
this.PointY.Text = touch.Y.ToString();
}
顺便使用SO Post
中的代码