locked
How can I keep a parent object's behavior triggers from overriding their childrens' behavior triggers? RRS feed

  • Question

  • What I've done is create a list in the form of a TreeView, with sub-sections included, each of which is supposed to navigate to a different part of the page by activating a different state. So for every TreeViewItem, there's one state. The problem is that when I use the ActivateState or GoToState, only the first-generation TreeViewItems function properly, but any of the child TreeViewItems just link to the same state as their parent TreeViewItem. Is there some way for the child to ignore the behavior of their parent so that they can function the same way as sub-lists within the tree?
    Thursday, February 23, 2012 9:35 PM

All replies

  • Hey Zombie...

    Take a look at this blog and see if it won't help your solve your problem.

    http://blogs.msdn.com/b/hulyap/archive/2008/07/07/mouseover-trigger-for-treeviewitem.aspx

    Basically what he/she says is that what is true for the child node is also true for the parent node.

    Another option would be to have a different trigger for the parent and one for the children like such...

    <Window
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	x:Class="WpfApplication5.MainWindow"
    	x:Name="Window"
    	Title="MainWindow"
    	Width="640" Height="480">
    	<Window.Resources>
    		<Storyboard x:Key="Storyboard1">
    			<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
    				<EasingColorKeyFrame KeyTime="0" Value="White"/>
    			</ColorAnimationUsingKeyFrames>
    		</Storyboard>
    		<Storyboard x:Key="Storyboard2">
    			<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
    				<EasingColorKeyFrame KeyTime="0" Value="Red"/>
    			</ColorAnimationUsingKeyFrames>
    		</Storyboard>
    		<Storyboard x:Key="Storyboard3">
    			<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
    				<EasingColorKeyFrame KeyTime="0" Value="Blue"/>
    			</ColorAnimationUsingKeyFrames>
    		</Storyboard>
    		<Storyboard x:Key="Storyboard4">
    			<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
    				<EasingColorKeyFrame KeyTime="0" Value="Yellow"/>
    			</ColorAnimationUsingKeyFrames>
    		</Storyboard>
    	</Window.Resources>
    	<Window.Triggers>
    		<EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonDown" SourceName="treeViewItem1">
    			<BeginStoryboard x:Name="Storyboard2_BeginStoryboard" Storyboard="{StaticResource Storyboard2}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonDown" SourceName="treeViewItem2">
    			<BeginStoryboard x:Name="Storyboard3_BeginStoryboard" Storyboard="{StaticResource Storyboard3}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonDown" SourceName="treeViewItem3">
    			<BeginStoryboard x:Name="Storyboard4_BeginStoryboard" Storyboard="{StaticResource Storyboard4}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="treeViewItem">
    			<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
    		</EventTrigger>
    	</Window.Triggers>
    
    	<Grid x:Name="LayoutRoot">
    		<TreeView HorizontalAlignment="Left" Width="213" Margin="0,0,0,175">
    			<TreeViewItem x:Name="treeViewItem" Header="My Colors" IsSelected="True" Height="128" IsExpanded="True" Cursor="Hand" Background="#0000FF04" FontSize="21.333">
    				<TreeViewItem x:Name="treeViewItem1" Header="Red" IsExpanded="True" Cursor="Hand" Background="#0000FF04" FontSize="21.333" Margin="0"/>
    				<TreeViewItem x:Name="treeViewItem2" Header="Blue" Margin="0" Cursor="Hand" Background="#0000FF04" FontSize="21.333"/>
    				<TreeViewItem x:Name="treeViewItem3" Header="Yellow" Cursor="Hand" Background="#0000FF04" FontSize="21.333" Margin="0"/>
    			</TreeViewItem>
    		</TreeView>
    		<Rectangle x:Name="rectangle" Height="100" Stroke="Black" VerticalAlignment="Top" Margin="239,8,285,0" Fill="White"/>
    	</Grid>
    </Window>

    It's a bit of an annoying situation you're in and I'm sorry for your troubles.

    Hope you get it worked out quickly and easily.

    ~Christine

    This blog also offers a bit more complicated solution...

    http://blogs.msdn.com/b/mikehillberg/archive/2006/09/21/mytreeviewhelperismousedirectlyoveritem.aspx

    Saturday, February 25, 2012 1:07 AM