Can you animate ZIndex for TemplatedParent in VisualStateManager?

I have a custom control on which I would like to add mouse behavior to bring the whole object to the beginning of the z-order, and then return it to the position when the mouse is over another object on the canvas.

I have the following XAML in which the color is being animated, the ZIndex of the rectangle inside the control is animating (shading the ellipse), but I cannot get the entire control to switch to all the other controls in the parent canvas. The complex part of XAML is shown with an empty string before and after below.

<Style TargetType="local:CustomControl1">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:CustomControl1">
                <Grid x:Name="PartLayoutRoot">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal" />
                            <VisualState x:Name="MouseOver">
                                <Storyboard>

                                    <Int32AnimationUsingKeyFrames 
                                            Storyboard.Target="{Binding RelativeSource={RelativeSource TemplatedParent} }"
                                            Storyboard.TargetProperty="(Canvas.ZIndex)">
                                        <DiscreteInt32KeyFrame KeyTime="0" Value="99" />
                                    </Int32AnimationUsingKeyFrames>

                                    <Int32AnimationUsingKeyFrames 
                                            Storyboard.TargetName="Rect"
                                            Storyboard.TargetProperty="(Canvas.ZIndex)">
                                        <DiscreteInt32KeyFrame KeyTime="0" Value="99" />
                                    </Int32AnimationUsingKeyFrames>
                                    <ColorAnimation To="Red" 
                                        Storyboard.TargetName="Rect" 
                                        Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
                                        Duration="0:0:1" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>

                    <Rectangle x:Name="Rect" Fill="Blue" Height="40" Width="40" />
                    <Ellipse Fill="Green" Height="30" Width="30" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

, ZIndex -, inter-control. , , . , , , , , . , ,

System.Windows.Data: 2: FrameworkElement FrameworkContentElement . BindingExpression: ( ); DataItem = NULL; "Int32AnimationUsingKeyFrames" (HashCode = 58939632); target - "Target" ( 'DependencyObject')

, , , , , . , XAML.

+4
1

ZIndex VisualState , .

<Style TargetType="local:CustomControl1">
    <Setter Property="Template">
        ...
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="(Canvas.ZIndex)" Value="99"/>
        </Trigger>
    </Style.Triggers>
</Style>

, !

0

Source: https://habr.com/ru/post/1536026/


All Articles