如何获取MouseOver触发器事件更改子项

时间:2013-05-07 15:06:12

标签: wpf xaml mouseover

我有一个MouseOver事件的边框。在那个边界内(进一步向下)我有几个带有RotateTransform的边界......我怎样才能在顶级Border悬停事件中改变他们的变换? (即改变他们的轮换?)

<Border.Style>
    <Style>
        <Style.Triggers>
            <Trigger Property="Border.IsMouseOver" Value="True">
                <Setter Property="Border.Background" Value="#f0f0f0" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Border.Style>

在树的下方,但在这个边界内是

<Border Padding="3" Width="73" Height="57" Background="White" RenderTransformOrigin="0.5, 0.5">
    <Border.Effect>
        <DropShadowEffect BlurRadius="4" Direction="0" ShadowDepth="0" Color="#aa505050" />
    </Border.Effect>
    <Border.RenderTransform>
         <RotateTransform Angle="-2" />
    </Border.RenderTransform>
</Border>

1 个答案:

答案 0 :(得分:2)

您可以在内部边框DataTrigger中使用Style FindAncestorElementName绑定来获取外边框的IsMouseOver

<Border.Style>
    <Style TargetType="Border">
        <Setter Property="RenderTransform">
            <Setter.Value>
                <RotateTransform Angle="3"/>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=IsMouseOver}" Value="True">
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <RotateTransform Angle="6"/>
                    </Setter.Value>
                </Setter>
            </DataTrigger >
        </Style.Triggers>
    </Style>
</Border.Style>