WPF-XAML-从父样式调用嵌套样式中的动画
我正在尝试修改ItemsControl,使其具有水印,以指示放入其中的内容的行为 我在VisualBrush中使用一个标签来显示单词“OR”作为ItemsControl的背景(该控件将包含属性过滤器,这些属性过滤器将被合并在一起)。背景更改由ItemsControl上的IsMouseOver触发 问题是:如果我直接在标签中设置不透明度,我可以让我的VisualBrush(参见xaml)显示/消失,但是如果我尝试使用嵌套样式作为标签,我无法让不透明度设置动画。我已经尝试了几种方法,但都没有成功,因此任何关于我的错误的建议都将受到感激 我已经包括(一个注释掉)我尝试过的两个动画。我还尝试用彩色动画在标签上设置前景,但没有成功 非常感谢 伊恩·卡森WPF-XAML-从父样式调用嵌套样式中的动画,wpf,xaml,animation,storyboard,visualbrush,Wpf,Xaml,Animation,Storyboard,Visualbrush,我正在尝试修改ItemsControl,使其具有水印,以指示放入其中的内容的行为 我在VisualBrush中使用一个标签来显示单词“OR”作为ItemsControl的背景(该控件将包含属性过滤器,这些属性过滤器将被合并在一起)。背景更改由ItemsControl上的IsMouseOver触发 问题是:如果我直接在标签中设置不透明度,我可以让我的VisualBrush(参见xaml)显示/消失,但是如果我尝试使用嵌套样式作为标签,我无法让不透明度设置动画。我已经尝试了几种方法,但都没有成功,因
<ItemsControl x:Name="OrFilterItemsTarget"
ItemsSource="{Binding Assets.OrFilters}"
ItemTemplateSelector="{StaticResource FilterTargetTemplateSelector}"
ItemContainerStyle="{StaticResource DraggableItemStyle}"
BorderThickness="0,0,0,0.5"
BorderBrush="DimGray"
AllowDrop="True"
IsHitTestVisible="True"
Margin="0,2.95,15.934,77"
HorizontalAlignment="Right"
Width="105">
<ItemsControl.Style>
<Style TargetType="{x:Type ItemsControl}">
<Style.Resources>
<Style x:Key="LabelStyle"
TargetType="{x:Type Label}">
<Style.Resources>
<Storyboard x:Key="FadeUp">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetProperty="Opacity"
FillBehavior="HoldEnd">
<SplineDoubleKeyFrame KeyTime="00:00:2"
Value="0.5" />
</DoubleAnimationUsingKeyFrames>
<!--<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="0" To="0.5"
Duration="0:0:2" />-->
</Storyboard>
<Storyboard x:Key="FadeDown">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetProperty="Opacity"
FillBehavior="Stop">
<SplineDoubleKeyFrame KeyTime="00:00:2"
Value="0" />
</DoubleAnimationUsingKeyFrames>
<!--<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="0.5" To="0"
Duration="0:0:2" />-->
</Storyboard>
</Style.Resources>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsMouseOver, ElementName=OrFilterItemsTarget}"
Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource FadeUp}" />
</DataTrigger.EnterActions>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsMouseOver, ElementName=OrFilterItemsTarget}"
Value="False">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource FadeDown}" />
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
<VisualBrush x:Key="FilterContentType"
AlignmentX="Center"
AlignmentY="Center"
Stretch="None">
<VisualBrush.Visual>
<Label Content="OR"
Foreground="DarkGray"
Style="{StaticResource LabelStyle}">
</Label>
</VisualBrush.Visual>
</VisualBrush>
</Style.Resources>
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="{StaticResource FilterContentType}" />
</Trigger>
<Trigger Property="IsMouseOver"
Value="False">
<Setter Property="Background"
Value="Transparent" />
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.Style>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"
Background="Transparent">
<i:Interaction.Behaviors>
<ei:FluidMoveBehavior AppliesTo="Children"
Duration="0:0:0.3">
<ei:FluidMoveBehavior.EaseY>
<BackEase EasingMode="EaseIn"
Amplitude="0.1" />
</ei:FluidMoveBehavior.EaseY>
</ei:FluidMoveBehavior>
</i:Interaction.Behaviors>
</WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
最后我意识到我对这个问题考虑得太多了。嵌套样式是不必要的。解决方案是将背景设置为ItemsControl中自己的标记内的VisualBrush(其内容设置为所需的最终外观),然后直接在ItemsControl上使用EventTriggers设置VisualBrush不透明度的动画。请注意用于管理鼠标和拖动用户活动的各种事件 感谢所有考虑过这个问题的人。最终的XAML看起来是这样的,希望对某些人有用
<ItemsControl x:Name="OrFilterItemsTarget"
ItemsSource="{Binding Assets.OrFilters}"
ItemTemplateSelector="{StaticResource FilterTargetTemplateSelector}"
ItemContainerStyle="{StaticResource DraggableItemStyle}"
BorderThickness="0,0,0,0.5"
BorderBrush="DimGray"
AllowDrop="True"
IsHitTestVisible="True"
Margin="0,2.95,15.934,77"
HorizontalAlignment="Right"
Width="105">
<ItemsControl.Background>
<VisualBrush x:Name="OrFilterContentType"
AlignmentX="Center"
AlignmentY="Center"
Stretch="None"
Opacity="0">
<VisualBrush.Visual>
<Label Content="OR"
Foreground="DarkGray"
Opacity="0.5" />
</VisualBrush.Visual>
</VisualBrush>
</ItemsControl.Background>
<ItemsControl.Triggers>
<EventTrigger RoutedEvent="ItemsControl.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="OrFilterContentType"
Storyboard.TargetProperty="(Brush.Opacity)"
From="0" To="1"
Duration="0:0:0.7" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="ItemsControl.DragEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="OrFilterContentType"
Storyboard.TargetProperty="(Brush.Opacity)"
From="0"
To="1"
Duration="0:0:0.7" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="ItemsControl.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="OrFilterContentType"
Storyboard.TargetProperty="(Brush.Opacity)"
From="1" To="0"
Duration="0:0:0.7" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="ItemsControl.DragLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="OrFilterContentType"
Storyboard.TargetProperty="(Brush.Opacity)"
From="1"
To="0"
Duration="0:0:0.7" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="ItemsControl.Drop">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="OrFilterContentType"
Storyboard.TargetProperty="(Brush.Opacity)"
From="1"
To="0"
Duration="0:0:0.7" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</ItemsControl.Triggers>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"
Background="Transparent">
<i:Interaction.Behaviors>
<ei:FluidMoveBehavior AppliesTo="Children"
Duration="0:0:0.3">
<ei:FluidMoveBehavior.EaseY>
<BackEase EasingMode="EaseIn"
Amplitude="0.1" />
</ei:FluidMoveBehavior.EaseY>
</ei:FluidMoveBehavior>
</i:Interaction.Behaviors>
</WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>