2012-07-22 272 views
0

我正在開發一個開源的虛擬鍵盤,但有一件事我真的沒有去工作: 我想創建一個輸入按鈕,就像在Windows奧斯卡上。但我怎樣才能讓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

你可以試試嗎?

<Grid> 
    <Button Content="Enter ⏎" 
      /> 
    <Button Content="K" 
      /> 

基本上它是使用U + 23CE字符Return symbol。當然更奇特的是你總是可以創建一個帶有自定義圖像的按鈕作爲內容

+0

感謝您的快速回答,但我想從按鈕,它看起來像鍵盤上的鍵。內容不是問題:) – 2012-07-22 18:10:58

+0

你所要求的是不可能的......不同的鍵盤有不同的輸入按鈕標籤。 – 2012-07-22 18:12:31