2010-12-08 28 views
0

J'applique un ItemContainerStyle à un contrôle ListBox. Dans mon style ListBoxItem j'ai plusieurs déclencheurs contenant des animations storyboard qui s'appliquent à l'état actuel de la ListBoxItem (IsSelected, IsMouseOver).ListBoxItem ControlTemplete.Triggers WPF

Tout fonctionne très bien et dandy jusqu'à ce que après avoir sélectionné un ListBoxItem, l'animation story-board IsMouseOver ne se déclenche pas pour le ListBoxItem qui a été précédemment sélectionné.

Je ne vois pas où est le problème, alors j'espère que quelqu'un va m'aider avec ce problème.

Vive

Voici le code que je utilise

<Style x:Key="ListBoxFeedItemStyle" TargetType="{x:Type ListBoxItem}"> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
    <Setter Property="Padding" Value="2,0,0,0"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
       <Border x:Name="Bd" Background="{TemplateBinding Background}" Margin="5" SnapsToDevicePixels="true"> 
        <Grid Name="Grid" Height="Auto" Margin="5"> 
         <TextBlock Margin="10" Text="{Binding Path=Name}" FontSize="14" TextTrimming="CharacterEllipsis" /> 
        </Grid> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" Value="true"> 
         <Trigger.EnterActions> 
          <BeginStoryboard> 
           <Storyboard> 
            <ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="Bd" Storyboard.TargetProperty="Background.Color" To="#4CDFDFDF" /> 
           </Storyboard> 
          </BeginStoryboard> 
         </Trigger.EnterActions> 
         <Trigger.ExitActions> 
          <BeginStoryboard> 
           <Storyboard> 
            <ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="Bd" Storyboard.TargetProperty="Background.Color" To="#00DFDFDF" /> 
           </Storyboard> 
          </BeginStoryboard> 
         </Trigger.ExitActions> 
        </Trigger> 
        <Trigger Property="IsSelected" Value="true"> 
         <Trigger.EnterActions> 
          <BeginStoryboard> 
           <Storyboard> 
            <ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="Bd" Storyboard.TargetProperty="Background.Color" To="#FFDFDFDF" /> 
           </Storyboard> 
          </BeginStoryboard> 
         </Trigger.EnterActions> 
         <Trigger.ExitActions> 
          <BeginStoryboard> 
           <Storyboard> 
            <ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="Bd" Storyboard.TargetProperty="Background.Color" To="#00DFDFDF" /> 
           </Storyboard> 
          </BeginStoryboard> 
         </Trigger.ExitActions> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

sauf si mon navigateur fonctionne mentalement, le code est généralement manquant ... – Tom

+0

Je n'arrive pas à obtenir le code à afficher lors du collage, car rien n'apparaît dans l'aperçu. J'ai dû utiliser Pastie. Utilisation de Chrome –

+0

Fixe. Je m'excuse pour tout inconvénient causé. –

Répondre

0

Vérifiez l'ordre de vos déclencheurs. Jetez un oeil à Multiple storyboards on one property

Découvrez la réponse de Yuri. Peut-être que c'est ce que vous cherchez.

+0

Parfait! Vive l'homme. –