似乎必须有办法做到这一点:
我在Listbox中应用了ItemContainerStyle,基于两个属性触发器。如您所见,我正在使用完全相同的触发器进入/退出操作集,只需应用于两个不同的属性。有没有等价于< Trigger Property =“prop1”OR Property =“prop2”> ??? (显然不会那样,但这可能会得到重点。)
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height"
To="50" Duration="0:0:.3"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height"
To="25" Duration="0:0:.3" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height"
To="50" Duration="0:0:.3"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height"
To="25" Duration="0:0:.3" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
答案 0 :(得分:1)
您是否尝试过以下任何一项(摘自Adam Nathan的书: Windows Presentation Foundation Unleashed ):
由于Style.Triggers可以包含多个触发器,因此您可以使用完全相同的Setter创建多个触发器来表示逻辑OR关系。
例如:
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
...
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
....
</Trigger>
</Style.Triggers>
这意味着,如果 IsMouseOver 为真或,如果 IsKeyboardFocusWithin 为true,则应用该操作。
要表达逻辑AND关系,您可以使用名为 MultiTrigger 的触发器的变体,或称为的 DataTrigger 的变体MultiDataTrigger 即可。两个触发器都有一个条件的集合,其中包含您通常直接放在Trigger或DataTrigger中的信息。
例如:
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition Property="IsKeyboardFocusWithin" Value="True"/>
</MultiTrigger.Conditions>
</MultiTrigger>
<Setter ...>
<Setter ...>
</Style.Triggers>
答案 1 :(得分:0)
您可以将故事板放入资源中,并在触发器中引用它们。它并不完全符合您的要求,但它允许您在一个中心位置定义动画(而不是必须复制和粘贴它们)。
<Style TargetType="...">
<Style.Resources>
<Storyboard x:Key="MyGetFocusAnimation">
<DoubleAnimation Storyboard.TargetProperty="Height"
To="50" Duration="0:0:.3" />
</Storyboard>
<Storyboard x:Key="MyLoseFocusAnimation">
<DoubleAnimation Storyboard.TargetProperty="Height"
To="25" Duration="0:0:.3" />
</Storyboard>
</Style.Resources>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource MyGetFocusAnimation}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource MyLoseFocusAnimation}" />
</Trigger.ExitActions>
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource MyGetFocusAnimation}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource MyLoseFocusAnimation}" />
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>