我在我的 WPF 用户控件的画布上包含了图像:
<Canvas>
<Thumb Canvas.Left="19" Canvas.Top="-7" Canvas.ZIndex="99" DragDelta="Thumb_DragDelta">
<Thumb.Template>
<ControlTemplate>
<Image Name="Image1" Source="/Images/Image1.png" Height="120" Width="242" Margin="63,180,696,393" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb Canvas.Left="52" Canvas.Top="6" DragDelta="Thumb_DragDelta">
<Thumb.Template>
<ControlTemplate>
<Image Name="Image2" Source="/Images/Image2.png" Height="120" Width="205" Margin="760,184,74,397" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb Canvas.Left="21" DragDelta="Thumb_DragDelta" Canvas.Top="-18">
<Thumb.Template>
<ControlTemplate>
<Image Name="Image3" Source="/Images/Image3.png" Height="124" Width="260" Margin="82,426,697,151" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb Canvas.Left="30" Canvas.Top="1" DragDelta="Thumb_DragDelta">
<Thumb.Template>
<ControlTemplate>
<Image Name="Image4" Source="/Images/Image4.png" Height="124" Width="255" Margin="744,341,39,236" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Canvas>
然后我在后面的代码中包含了以下内容,以便这些拇指图像可以在屏幕上移动,效果很好。
// Move images on canvas
private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
UIElement thumb = e.Source as UIElement;
Canvas.SetLeft(thumb, Canvas.GetLeft(thumb) + e.HorizontalChange);
Canvas.SetTop(thumb, Canvas.GetTop(thumb) + e.VerticalChange);
}
有谁知道快速添加,我可以在画布上用拇指添加到此代码中,以便我可以选择在不同方向和不同角度单击按钮时旋转这些图像?
谢谢