2008-12-20 175 views
3

在我的自定義按鈕,我需要顯示它有焦點(提供一些觸覺按鈕切換),並顯示它的按下,但我發現的是我的焦點狀態顯示,而不是我的按下狀態。我該如何糾正這一點。我想有鼠標懸停按下不鼠標,然後集中(當點擊按鈕時)Silverlight按鈕風格如何防止按下按鈕時的聚焦狀態?

這是我的控制模板的示例。

<UserControl.Resources> 
    <Style x:Key="GavelButtonStyle" TargetType="Button"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="Button"> 
        <Grid Background="#FF000000" x:Name="grid"> 
         <vsm:VisualStateManager.VisualStateGroups> 
          <vsm:VisualStateGroup x:Name="FocusStates"> 
           <vsm:VisualState x:Name="Unfocused"/> 
           <vsm:VisualState x:Name="Focused"> 
            <Storyboard> 
             <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)"> 
              <SplineColorKeyFrame KeyTime="00:00:00" Value="#FFFFFFFF"/> 
             </ColorAnimationUsingKeyFrames> 
             <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="grid" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"> 
              <SplineColorKeyFrame KeyTime="00:00:00" Value="#FF2844B9"/> 
             </ColorAnimationUsingKeyFrames> 
            </Storyboard> 
           </vsm:VisualState> 
          </vsm:VisualStateGroup> 
          <vsm:VisualStateGroup x:Name="CommonStates"> 
           <vsm:VisualStateGroup.Transitions> 
            <vsm:VisualTransition GeneratedDuration="00:00:00.2000000"/> 
           </vsm:VisualStateGroup.Transitions> 
           <vsm:VisualState x:Name="MouseOver"> 
            <Storyboard> 
             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"> 
              <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.5"/> 
             </DoubleAnimationUsingKeyFrames> 
             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"> 
              <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.5"/> 
             </DoubleAnimationUsingKeyFrames> 
            </Storyboard> 
           </vsm:VisualState> 
           <vsm:VisualState x:Name="Normal"/> 
           <vsm:VisualState x:Name="Pressed"> 
            <Storyboard> 
             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"> 
              <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5"/> 
             </DoubleAnimationUsingKeyFrames> 
             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"> 
              <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5"/> 
             </DoubleAnimationUsingKeyFrames> 
            </Storyboard> 
           </vsm:VisualState> 
           <vsm:VisualState x:Name="Disabled"/> 
          </vsm:VisualStateGroup> 
         </vsm:VisualStateManager.VisualStateGroups> 
         <Image Cursor="Hand" x:Name="image" RenderTransformOrigin="0.5,0.5" Source="11_64x64.png" Stretch="Fill" OpacityMask="#FF000000"> 
          <Image.RenderTransform> 
           <TransformGroup> 
            <ScaleTransform/> 
            <SkewTransform/> 
            <RotateTransform/> 
            <TranslateTransform/> 
           </TransformGroup> 
          </Image.RenderTransform> 
         </Image> 
         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</UserControl.Resources>; 
+0

你可以發佈你的XAML嗎? – bendewey 2008-12-21 02:47:06

回答

1

當你按下它變得專注,不能做關於什麼...你可以清除視覺狀態管理的重點內容,然後它不會集中,但它獲得的焦點從無論你做什麼,鼠標交互。

0

我已成功將IsTabStop設置爲False。我不希望它在單擊後阻止焦點,但似乎是它的作用。點擊按鈕後,空格鍵不被捕獲。

相關問題