我有一个看起来像指南针的 Silverlight 用户控件。我会发布图片,但我是新用户,还不能发布图片。:(。
本质上是一个外椭圆,在里面是一个中心的内椭圆,一个矩形作为指南针的“手”。我在下面发布了 xaml。
当鼠标左键按下并移动鼠标时,我想移动指南针“手”。我认为使用 RotateTransform 会相对容易,但我无法弄清楚。
我遇到的问题是
A. 我不知道如何设置 RotationTransform 的 CenterX、CenterY 和 Angle 属性。我希望手(红色矩形)围绕中心椭圆(中间的棕色椭圆)旋转。
B. 他们是减慢旋转变换的方法吗?因此,如果有人快速旋转鼠标,则手会移动,但不会像用户移动鼠标那么快。另一种说法是他们降低鼠标移动灵敏度的方法吗?
我会发布我的代码,但这很可悲。:-)。我不需要一个确切的解决方案,只需朝着正确的方向轻推。
这是 XAML
<Grid Margin="20,20,0,18" HorizontalAlignment="Left" Width="180">
<Ellipse x:Name="outerEllipse" Stroke="Black">
<Ellipse.Fill>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="#3FF7F5F5" Offset="0.449"/>
<GradientStop Color="#FFF7F1F1" Offset="0.938"/>
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Ellipse x:Name="innerEllipse" Margin="16,14,16,13" Stroke="Black">
<Ellipse.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFD8BABA" Offset="0"/>
<GradientStop Color="#FFF7F1F1" Offset="1"/>
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Ellipse x:Name="knobEllipse" Margin="83,75,82,74" Stroke="Black" Fill="#FFCFB53B"/>
<TextBlock x:Name="textNorth" Height="17" Margin="83,14,83,0" TextWrapping="Wrap" Text="N" VerticalAlignment="Top" Foreground="#FFCC3131" FontSize="16" FontFamily="Book Antiqua"/>
<TextBlock x:Name="textNorthEast" Height="21" Margin="0,34,25.666,0" TextWrapping="Wrap" Text="NE" VerticalAlignment="Top" Foreground="#FFCC3131" FontSize="16" FontFamily="Book Antiqua" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto" HorizontalAlignment="Right" Width="30">
<TextBlock.RenderTransform>
<CompositeTransform Rotation="45"/>
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock x:Name="textSouth" Height="17" Margin="86,0,85,13" TextWrapping="Wrap" Text="S" VerticalAlignment="Bottom" Foreground="#FFCC3131" FontSize="16" FontFamily="Book Antiqua"/>
<TextBlock x:Name="textNorthWest" Height="21" Margin="29,31,0,0" TextWrapping="Wrap" Text="NW" VerticalAlignment="Top" Foreground="#FFCC3131" FontSize="16" FontFamily="Book Antiqua" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto" HorizontalAlignment="Left" Width="30">
<TextBlock.RenderTransform>
<CompositeTransform Rotation="315"/>
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock x:Name="textEast" HorizontalAlignment="Right" Margin="0,75,16,74" TextWrapping="Wrap" Text="E" Width="11" Foreground="#FFCC3131" FontSize="16" FontFamily="Book Antiqua"/>
<TextBlock x:Name="textWest" HorizontalAlignment="Left" Margin="16,73,0,72" TextWrapping="Wrap" Text="W" Width="20" Foreground="#FFCC3131" FontSize="16" FontFamily="Book Antiqua"/>
<TextBlock x:Name="textSouthEast" Margin="0,0,33.834,25.333" TextWrapping="Wrap" Text="SE" Foreground="#FFCC3131" FontSize="16" FontFamily="Book Antiqua" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto" HorizontalAlignment="Right" Height="21" VerticalAlignment="Bottom" Width="30">
<TextBlock.RenderTransform>
<CompositeTransform Rotation="140"/>
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock x:Name="textSouthWest" Margin="31.5,0,0,29.5" TextWrapping="Wrap" Text="SW" Foreground="#FFCC3131" FontSize="16" FontFamily="Book Antiqua" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto" HorizontalAlignment="Left" Width="30" Height="21" VerticalAlignment="Bottom">
<TextBlock.RenderTransform>
<CompositeTransform Rotation="220"/>
</TextBlock.RenderTransform>
</TextBlock>
<Rectangle x:Name="rectanglePointer" Height="32" Margin="87,43,86,0" Stroke="Black" VerticalAlignment="Top">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFF38989" Offset="0"/>
<GradientStop Color="#FF914949" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
谢谢你的帮助