Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Custom TabItem template with MouseLeftButtonDown event states

$
0
0

I have created a template for my TabItems within a TabControl.   I have looks defined for the Selected and Unselected states.  I want to also have a Down Pressed look for both the Selected and Unselected States when you click the mouse on a selected or unselected tab.

I have used the defualt SelectionStates VisualStateGroup for Selected and Unselected states to set the view of the tab.  

<VisualStateGroup x:Name="SelectionStates"><VisualState x:Name="Selected"><Storyboard><ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="tab_ON"><DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/></ObjectAnimationUsingKeyFrames></Storyboard></VisualState><VisualState x:Name="Unselected"><Storyboard><ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="tab_OFF"><DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/></ObjectAnimationUsingKeyFrames></Storyboard></VisualState></VisualStateGroup>

Now I want to change the look based on a MouseLeftButtonDown RoutedEvent using an EventTrigger.   I created a Storyboard for displaying my Unselected Mouse Down view.   But it doesn't seem to be displaying because the VisualStateGroup overrides it since the tab is either in a Selected or Unselected state at all times.    How is this normally done?   I'm sure that having Selected, Unselected, Mouse Down, and Mouse Over views of a TabItem is a common feature. What I do with other controls that have a Pressed state is use  MultiTrigger and MultiTrigger.Conditions to set the views based on a boolean and the current IsMouseOver, IsPressed state.  But IsPressed isn't available for TabItem?

<ControlTemplate.Resources><Storyboard x:Key="OnMouseLeftButtonDown1"><ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="tab_graph_OFF_DOWN"><DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/></ObjectAnimationUsingKeyFrames></Storyboard></ControlTemplate.Resources>

<ControlTemplate.Triggers><EventTrigger RoutedEvent="UIElement.MouseLeftButtonDown"><BeginStoryboard Storyboard="{StaticResource OnMouseLeftButtonDown1}"/></EventTrigger></ControlTemplate.Triggers>

 

Jeff Davis



Viewing all articles
Browse latest Browse all 18858

Trending Articles