2010-12-07 101 views
1

我想知道是否有可能暂停onMouserOver状态,而单选按钮被选中/选择。我有一个原型,通过点击重新设置的单选按钮切换内容。当选中单选按钮时,我需要保持选中状态不变。现在,当鼠标滚动/展开发生时,它改变了背景颜色,假设在没有选择按钮时发生改变。以下是代码。先谢谢你。选择单选按钮时,如何禁止onMouseOver/Out状态?

<StackPanel> 
    <RadioButton x:Name="one" Content="one" IsChecked="True" GroupName="intro" Style="{DynamicResource RadioButtons}" Style="{DynamicResource RadioButtons}" /> 
    <RadioButton x:Name="two" Content="two" IsChecked="True" GroupName="intro" Style="{DynamicResource RadioButtons}" Style="{DynamicResource RadioButtons}" /> 
    <RadioButton x:Name="three" Content="three" IsChecked="True" GroupName="intro" Style="{DynamicResource RadioButtons}" Style="{DynamicResource RadioButtons}" /> 
</StackPanel> 

风格:

<Style x:Key="IntroRadioButtons" TargetType="{x:Type RadioButton}"> 
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
    <Setter Property="Background" Value="#F4F4F4"/> 
    <Setter Property="BorderBrush" Value="{StaticResource CheckBoxStroke}"/> 
    <Setter Property="BorderThickness" Value="1"/> 
    <Setter Property="Template"> 
    <Setter.Value> 
    <ControlTemplate TargetType="{x:Type RadioButton}"> 

     <Border HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
     Margin="{TemplateBinding Padding}" 
     VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
     x:Name="borderRadioButon" BorderBrush="{x:Null}" BorderThickness="0" 
     Background="#FFFFB343" Width="90" Height="90" > 

     <VisualStateManager.VisualStateGroups> 
     <VisualStateGroup x:Name="CommonStates"> 
     <VisualState x:Name="Normal"/> 
     <VisualState x:Name="MouseOver"> 
     <Storyboard> 
      <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="borderRadioButon"> 
      <EasingColorKeyFrame KeyTime="0" Value="#FFFD7713"/> 
      </ColorAnimationUsingKeyFrames> 
     </Storyboard> 
     </VisualState> 
     <VisualState x:Name="Pressed"> 
     <Storyboard> 
      <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="borderRadioButon"> 
      <EasingColorKeyFrame KeyTime="0" Value="#FFFD7713"/> 
      </ColorAnimationUsingKeyFrames> 
     </Storyboard> 
     </VisualState> 
     <VisualState x:Name="Disabled"/> 
     </VisualStateGroup> 
     <VisualStateGroup x:Name="CheckStates"> 
     <VisualState x:Name="Checked"> 
     <Storyboard> 
      <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="borderRadioButon"> 
      <EasingColorKeyFrame KeyTime="0" Value="#FFFD7713"/> 
      </ColorAnimationUsingKeyFrames> 
     </Storyboard> 
     </VisualState> 
     <VisualState x:Name="Unchecked"/> 
     <VisualState x:Name="Indeterminate"/> 
     </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 

     <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
     Margin="0,0,0,4" HorizontalAlignment="Center" VerticalAlignment="Bottom" 
     TextBlock.FontSize="{DynamicResource PrimaryFontSize}" 
     TextBlock.FontFamily="{DynamicResource PrimaryFontFamily}"  
     /> 

    </Border> 

    <ControlTemplate.Triggers> 
     <Trigger Property="HasContent" Value="true"> 
     <Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/> 
     <Setter Property="Padding" Value="4,0,0,0"/> 
     </Trigger> 
     <Trigger Property="IsEnabled" Value="false"> 
     <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
     </Trigger> 
    </ControlTemplate.Triggers> 
    </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
</Style> 

回答

1

类似的问题here。看起来像两个VisualStateGroup的冲突,当他们针对相同的控件相同的属性。使用与链接相同的方法,它似乎正在工作:添加了两个边框,每个组一个边框。如果有更好的方法可以解决这个问题,那么我也会对它感兴趣:)

<Style x:Key="IntroRadioButtons" TargetType="{x:Type RadioButton}"> 
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
    <Setter Property="Background" Value="#F4F4F4"/> 
    <Setter Property="BorderBrush" Value="{StaticResource CheckBoxStroke}"/> 
    <Setter Property="BorderThickness" Value="1"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type RadioButton}"> 
       <Grid> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="CommonStates"> 
          <VisualState x:Name="Normal"/> 
          <VisualState x:Name="MouseOver"> 
           <Storyboard> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="borderRadioButon"> 
             <EasingColorKeyFrame KeyTime="0" Value="#FFFD7713"/> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Pressed"> 
           <Storyboard> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="borderRadioButon"> 
             <EasingColorKeyFrame KeyTime="0" Value="#FFFD7713"/> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Disabled"/> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="CheckStates"> 
          <VisualState x:Name="Checked"> 
           <Storyboard> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="borderRadioButon2"> 
             <EasingColorKeyFrame KeyTime="0" Value="#FFFD7713"/> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Unchecked"/> 
          <VisualState x:Name="Indeterminate"/> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
        <Border HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
          Margin="{TemplateBinding Padding}" 
          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
          x:Name="borderRadioButon" BorderBrush="{x:Null}" BorderThickness="0" 
          Background="#FFFFB343" Width="90" Height="90"> 
         <Border HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
           Margin="0" 
           VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
           x:Name="borderRadioButon2" BorderBrush="{x:Null}" BorderThickness="0" 
           Background="Transparent" Width="90" Height="90"> 
          <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
              Margin="0,0,0,4" HorizontalAlignment="Center" VerticalAlignment="Bottom" 
              TextBlock.FontSize="{DynamicResource PrimaryFontSize}" 
              TextBlock.FontFamily="{DynamicResource PrimaryFontFamily}"/> 
         </Border> 
        </Border> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="HasContent" Value="true"> 
         <Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/> 
         <Setter Property="Padding" Value="4,0,0,0"/> 
        </Trigger> 
        <Trigger Property="IsEnabled" Value="false"> 
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

谢谢你的提示。它解决了眼前的问题。如果我找到其他方法,我会告诉你。 – vladc77 2010-12-07 23:29:49