属性触发器通常是在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>
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