在UserControl中添加触发器



我有UserControl: Grid, Border, Image, Button。我需要为我的UserControl创建样式,并在这个样式中创建触发器。我的风格:

<Style x:Key="SlideControlGrid" TargetType="{x:Type UserControl}">
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="False">
            <Setter Property="Opacity" Value="0.5"></Setter>
        </Trigger>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Opacity" Value="1"></Setter>
        </Trigger>
    </Style.Triggers>
</Style>

但是我必须绑定我的样式与我的UserControl在XAML文件?

只需要添加DynamicResource。我的绑定:

<UserControl.Style>
    <DynamicResource ResourceKey="SlideControlGrid"/>
</UserControl.Style>

My Style in another file Style.xaml:

<Style x:Key="SlideControlGrid" TargetType="{x:Type UserControl}">
    <Setter Property="Background" Value="Yellow" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Opacity" Value="0.5" />
        </Trigger>
        <Trigger Property="IsMouseOver" Value="False">
            <Setter Property="Opacity" Value="1" />
        </Trigger>
    </Style.Triggers>
</Style>

相关内容

  • 没有找到相关文章

最新更新