WPF,UserControl里面怎么样使用触发器

.Net技术 码拜 9年前 (2016-03-11) 1832次浏览
属性触发器通常是在Style和ControlTemplate中使用的,在UserControl的XAML代码中怎么样使用属性触发器呢?
解决方案

27

<UserControl x:Class=”WpfApplication10.UserControl2″
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″
mc:Ignorable=”d”
d:DesignHeight=”300″ d:DesignWidth=”300″>
<UserControl.Style>
<Style TargetType=”UserControl”>
<Style.Triggers>
</Style.Triggers>
</Style>
</UserControl.Style>
<Grid>

</Grid>
</UserControl>
UserControl也有Style啊

10

UserControl也是DependencyObject,同样有Style和ControlTemplate,触发器该怎么用就怎么用

27

    <UserControl.Style>
        <Style>
            <Style.Triggers>
                
            </Style.Triggers>
        </Style>
    </UserControl.Style>
    <UserControl.Template>
        <ControlTemplate>
            <ControlTemplate.Triggers>
                
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </UserControl.Template>

25

 <UserControl.Resources>
        <Storyboard x:Key="OnMouseEnter1">
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="userControl">
                <EasingColorKeyFrame KeyTime="0" Value="Red"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="Mouse.MouseEnter">
            <BeginStoryboard Storyboard="{StaticResource OnMouseEnter1}"/>
        </EventTrigger>
    </UserControl.Triggers>

https://social.msdn.microsoft.com/Forums/zh-CN/d2a199ed-4cf3-48d0-9055-9fdc857f500c/datatriggervalue-usercontrol


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明WPF,UserControl里面怎么样使用触发器
喜欢 (0)
[1034331897@qq.com]
分享 (0)