繁体   English   中英

如何在IsMouseOver触发器上更改UserControl的子元素的属性?

[英]How to change a property of a UserControl's child element on a IsMouseOver trigger?

我有一个自定义用户控件,该控件具有轮廓边框,当鼠标悬停在控件上时,我想以某种方式突出显示该边框。 我试图用鼠标悬停触发器向用户控件添加样式,但是没有找到如何定位子边框的样式(样式目标名似乎找不到“ OuterBorder”)。

将触发器添加到边框本身似乎根本不起作用。

<UserControl x:Class="CCC.Controls.Test"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:CCC.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="240" d:DesignWidth="182" Height="240" Width="182" Margin="2" >
    <!-- tried to add trigger here too as UserControl.Style -->
    <Grid>
        ... <!-- other controls inside here -->
        <Border x:Name="OuterBorder" Width="182" CornerRadius="3"  BorderThickness="3" BorderBrush="#acacac" Margin="0,00,0,0" Height="240" VerticalAlignment="Top">
            <!-- doesnt work -->
            <Border.Style>
                <Style>
                    <Style.Triggers>
                        <Trigger Property="Border.IsMouseOver" Value="True">
                            <Setter Property="Border.BorderBrush" Value="Red"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
        </Border>
    </Grid>
</UserControl>

感谢您的任何想法!

您已将BorderBrush属性的Local Value设置为acacac 此本地值将优先。 请参阅属性值优先级

  1. Border设置Background=Transparent

  2. Border标签中删除BorderBrush并进行以下更改:

     <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" Value="Red"/> </Trigger> <Trigger Property="IsMouseOver" Value="False"> <Setter Property="BorderBrush" Value="#acacac"/> </Trigger> </Style.Triggers> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM