2009-10-16 9 views
1

Je cette XamlWPF SystemColors.HighlightTextBrushKey IsFrozen = True; Comment changer de premier plan sur l'élément sélectionné contrôle ListBox

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" 
    Value="#123456"/>   
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" 
    Value="White"/> 

Le premier fonctionne, le second ne fonctionne pas. Sur MSDN, SystemColors.HighlightTextBrushKey dit qu'il « IsFrozen » et ne peut être changé, donc j'ai essayé dans mon style:

<Trigger Property="IsSelected" Value="true"> 
    <Setter Property="Foreground" Value="White" /> 
</Trigger> 

Ce qui ne fonctionne pas non plus, aucune indication serait vraiment utile, merci.

Modifier - Xaml supplémentaires

<ListBox ItemContainerStyle="{DynamicResource ListBoxItemStyle}" 
     AlternationCount="2" 
     Margin="8,37,8,74" 
     x:Name="listClientOUContents" 
     HorizontalContentAlignment="Stretch"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Grid Height="22" HorizontalAlignment="Stretch"> 
        <Image Margin="-2,0,0,0" Source="{Binding Path=ADsPath, Converter={StaticResource ImxConverter}}" HorizontalAlignment="Left" Width="22" /> 
        <TextBlock HorizontalAlignment="Stretch" Margin="20,3,0,0" Text="{Binding Path=DisplayValue}" /> 
        <Rectangle HorizontalAlignment="Stretch" Fill="White" Stroke="White" Margin="-2,0,-2,0.5" VerticalAlignment="Bottom" Height="1" /> 
       </Grid> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 

est le ItemContainerStyle Je suis ici en utilisant

<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}"> 
     <Setter Property="FontSize" Value="12" /> 
     <Setter Property="FontFamily" Value="Tahoma" /> 
     <Setter Property="Background" Value="#006C3B3B"/> 
     <Style.Resources> 
      <!-- Selected and Focused --> 
      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF533F70"/> 
      <!-- Selected and UN-focused --> 
      <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FF533F70"/> 
      <Storyboard x:Key="MouseOverStoryBoard"> 
       <ColorAnimationUsingKeyFrames AutoReverse="True" BeginTime="00:00:00" Storyboard.TargetName="{x:Null}" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"> 
        <SplineColorKeyFrame KeyTime="00:00:00" Value="#FFF48F21"/> 
        <SplineColorKeyFrame KeyTime="00:00:00.5000000" Value="#FF4A475C"/> 
       </ColorAnimationUsingKeyFrames> 
      </Storyboard> 
     </Style.Resources> 
     <Style.Triggers> 
      <Trigger Property="IsSelected" Value="true"> 
       <Setter Property="Foreground" Value="White" /> 
      </Trigger> 
      <Trigger Property="ItemsControl.AlternationIndex" Value="0"> 
       <Setter Property="Background"> 
        <Setter.Value> 
         <SolidColorBrush Color="#a1a1a1"/> 
        </Setter.Value> 
       </Setter> 
       <Setter Property="Foreground" Value="black"/> 
      </Trigger> 
      <Trigger Property="ItemsControl.AlternationIndex" Value="1"> 
       <Setter Property="Background" Value="#a1a1a1"/> 
       <Setter Property="Foreground" Value="black"/> 
      </Trigger> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Trigger.EnterActions> 
        <BeginStoryboard Storyboard="{StaticResource MouseOverStoryBoard}"/> 
       </Trigger.EnterActions> 
       <Setter Property="Foreground" Value="White" /> 
       <Setter Property="Background" Value="#FFF48F21"/> 
       <Setter Property="FontStyle" Value="Normal"/> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 
+0

Pouvez-vous afficher plus de votre XAML (l'élément ListBox et tous les éléments pertinents contenus dans votre zone de liste)? – Scott

+0

Oui ... J'ai modifié la question avec plus de xaml. – Nate

Répondre

1

Edit: intervertir l'ordre de votre déclencheur 'IsSelected' et votre « ItemsControl.AlternationIndex «déclencheur:

<Trigger Property="ItemsControl.AlternationIndex" Value="0"> 
    <Setter Property="Background"> 
     <Setter.Value> 
      <SolidColorBrush Color="#a1a1a1"/> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="Foreground" Value="black"/> 
</Trigger> 
<Trigger Property="IsSelected" Value="true"> 
    <Setter Property="Foreground" Value="White" /> 
</Trigger> 

Le le dernier déclencheur de la liste est prioritaire, donc votre AlternationIndex remplaçait votre déclencheur IsSelected. Avec IsSelected étant listé après l'AlternationIndex, il devrait maintenant avoir la priorité.

Questions connexes