2010-12-07 7 views
1

Ich frage mich, ob es möglich ist, onMouserOver Zustand zu stoppen, während Radio-Button aktiviert/ausgewählt ist. Ich habe einen Prototyp, bei dem ich den Inhalt durch Klicken auf neu gestaltete Optionsfelder umstelle. Ich muss den ausgewählten Status beibehalten, während der Auswahlknopf nicht geändert wird. Wenn nun ein Maus-Rollover/Rollout durchgeführt wurde, änderte sich die Hintergrundfarbe, die sich ändern sollte, wenn die Schaltfläche nicht ausgewählt wurde. Unten ist der Code. Vielen Dank im Voraus.Wie kann onMouseOver/Out nicht aktiviert werden, während die Optionsschaltfläche ausgewählt ist?

<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> 

Stil:

<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> 

Antwort

1

ähnliche Frage here. Scheint wie der Konflikt der beiden VisualStateGroups, wenn sie dieselbe Eigenschaft für dasselbe Steuerelement anvisieren. Verwendet den gleichen Ansatz wie in der Verknüpfung und es scheint zu funktionieren: Zwei Grenzen, eine für jede Gruppe hinzugefügt. Wenn es einen besseren Weg gibt, das zu lösen, als ich interessiert bin, was das auch ist :)

<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

Vielen Dank für den Tipp. Es behebt das unmittelbare Problem. Ich werde dich wissen lassen, wenn ich anders herum finde. – vladc77

Verwandte Themen