UserControl as ListBoxItem and IsSelected

Posted by mattjf on Stack Overflow See other posts from Stack Overflow or by mattjf
Published on 2010-05-02T21:40:18Z Indexed on 2010/05/02 21:48 UTC
Read the original article Hit count: 321

Filed under:
|
|

I have a usercontrol that I want to use as a ListBoxItem.

<ListBox.ItemTemplate>
     <DataTemplate>
          <local:MyUserControl/>
     </DataTemplate>
</ListBox.ItemTemplate>

I'd like to play a storyboard when the usercontrol is unselected.

<UserControl.Resources>
     <Style TargetType="{x:Type UserControl}">
          <Style.Triggers>
               <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="False">
                    <DataTrigger.EnterActions>
                         <BeginStoryboard Storyboard="{StaticResource OnMouseLeaveSB}"/>
                    </DataTrigger.EnterActions>
               </DataTrigger>
          </Style.Triggers>
     </Style>
 </UserControl.Resources>

But the storyboard is never firing. Is there a better way to do this?

Edited to Add:

What I am really trying to accomplish this this:

When the mouse is over the UserControl, I want to play a storyboard (OnMouseEnterSB). When the mouse leaves the UserControl, I want to play another storyboard (OnMouseLeaveSB). I have all this working fine.

When the UserControl is selected, however, and the mouse leaves, I do NOT want to play the storyboard.

Finally, when the UserControl is unselected, I want to play the OnMouseLeaveSB storyboard.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about expression-blend