在 WPF 中,RenderTransform
可以通过这种方式大致旋转控件:
<Label Width="50" Height="20">
<Label.RenderTransform>
<RotateTransform Angle="90" />
</Label.RenderTransform>
</Label>
在这种情况下,Label
旋转 90 度。但是Window
无法旋转 chrome 的对象,因为Window
现在 GDI 仍在渲染 chrome。
在您的情况下,我可以建议为符合您要求的 WPF查找/创建/等键盘控件。例如,我通过链接找到了这样一个控件:
为了增加控件的旋转,我添加了两个按钮:RotateOn180
和RotateOn360
in VirtualKeyboard.xaml
。键盘本身在停靠面板中,所以我写了这个:
<DockPanel Width="500" Height="200" RenderTransformOrigin="0.5,0.5">
<DockPanel.RenderTransform>
<RotateTransform x:Name="KeyboardRotation" Angle="0"/>
</DockPanel.RenderTransform>
....
通过单击按钮启动动画,改变旋转角度。完整的附加代码:
<Grid>
<Grid.Triggers>
<EventTrigger SourceName="RotateOn180" RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard Storyboard.TargetName="KeyboardRotation" Storyboard.TargetProperty="Angle">
<DoubleAnimation From="0" To="180" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger SourceName="RotateOn360" RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard Storyboard.TargetName="KeyboardRotation" Storyboard.TargetProperty="Angle">
<DoubleAnimation From="180" To="360" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<Button Name="RotateOn180" Content="RotateOn180" Width="80" Height="30" HorizontalAlignment="Left" />
<Button Name="RotateOn360" Content="RotateOn360" Width="80" Height="30" HorizontalAlignment="Left" Margin="0,80,0,0" />
<DockPanel Width="500" Height="200" RenderTransformOrigin="0.5,0.5">
<DockPanel.RenderTransform>
<RotateTransform x:Name="KeyboardRotation" Angle="0"/>
</DockPanel.RenderTransform>
...Below is a standard code of project...
Output