2010-12-07 3 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。同じコントロールの同じプロパティを対象とする場合、2つのVisualStateGroupの競合のように見えます。リンクと同じアプローチを使用していて、動作しているようです:各グループに1つずつ、2つのボーダーを追加しました。これを解決するより良い方法があれば、私はそれもまた興味があります:)

<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

関連する問題