我正在开发一个开源虚拟键盘,但有一件事我真的没有工作: 我想创建一个像Windows osk上的那个按钮。但是我如何让WPF将其作为按钮绘制?
这是我的按钮代码:
<Style x:Key="EnterButton" BasedOn="{StaticResource KeyboardButton}" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Rectangle Fill="{TemplateBinding Background}" Stroke="#FF000000" StrokeThickness="1" RadiusX="5" RadiusY="50" Height="68" HorizontalAlignment="Center" x:Name="rectangle" VerticalAlignment="Top" Width="100"/>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonDown">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.0500000" Value="0.18"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonUp">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.18"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.0500000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
任何人都可以帮助我吗?
答案 0 :(得分:0)
你能试试吗?
<Grid>
<Button Content="Enter ⏎"
/>
<Button Content="K"
/>
基本上它使用Return symbol的 U + 23CE 字符。当然,您可以随时创建一个自定义图像作为内容的按钮