3

在一个UserControl我有一个类型enumGroupStyle类型eGroupStyle)的DP和一个类型boolIsGrouped)的DP。我需要在所有可能的情况下开始一些故事板。但MultiDataTrigger只有最后一个有效。我哪里错了?另外我想知道是否存在一种更简单的方法来考虑这些条件。(检查IsGrouped一次。)

C#:

enum eGroupStyle
{
    GroupStyle1,
    GroupStyle2,
    ∙∙∙,
    GroupStyleN,
}

XAML:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding GroupStyle}" Value="GroupStyle1"/>
        <Condition Binding="{Binding IsGrouped}" Value="False"/>
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.EnterActions>
        <BeginStoryboard  Storyboard="{StaticResource Storyboard_TurnToUnselectedStyle1}"/>
    </MultiDataTrigger.EnterActions>
</MultiDataTrigger>
<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding GroupStyle}" Value="GroupStyle1"/>
        <Condition Binding="{Binding IsGrouped}" Value="True"/>
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.EnterActions>
        <BeginStoryboard  Storyboard="{StaticResource Storyboard_TurnToSelectedStyle1}"/>
    </MultiDataTrigger.EnterActions>
</MultiDataTrigger>
<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding GroupStyle}" Value="GroupStyle2"/>
        <Condition Binding="{Binding IsGrouped}" Value="False"/>
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.EnterActions>
        <BeginStoryboard  Storyboard="{StaticResource Storyboard_TurnToUnselectedStyle2}"/>
    </MultiDataTrigger.EnterActions>
</MultiDataTrigger>
<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding GroupStyle}" Value="GroupStyle2"/>
        <Condition Binding="{Binding IsGrouped}" Value="True"/>
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.EnterActions>
        <BeginStoryboard  Storyboard="{StaticResource Storyboard_TurnToSelectedStyle2}"/>
    </MultiDataTrigger.EnterActions>
</MultiDataTrigger>
∙∙∙
<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding GroupStyle}" Value="GroupStyleN"/>
        <Condition Binding="{Binding IsGrouped}" Value="False"/>
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.EnterActions>
        <BeginStoryboard  Storyboard="{StaticResource Storyboard_TurnToUnselectedStyleN}"/>
    </MultiDataTrigger.EnterActions>
</MultiDataTrigger>
<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding GroupStyle}" Value="GroupStyleN"/>
        <Condition Binding="{Binding IsGrouped}" Value="True"/>
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.EnterActions>
        <BeginStoryboard  Storyboard="{StaticResource Storyboard_TurnToSelectedStyleN}"/>
    </MultiDataTrigger.EnterActions>
</MultiDataTrigger>
4

1 回答 1

9

我发现了!我需要在退出操作中删除以前的故事板,如下所示。现在它可以工作了:)

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding Path=GroupStyle}" Value="GroupStyle1"/>
        <Condition Binding="{Binding Path=IsGrouped}" Value="False"/>
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.EnterActions>
        <BeginStoryboard x:Name="BeginStoryboard_TurnToUnselectedStyle1" Storyboard="{StaticResource Storyboard_TurnToUnselectedStyle1}"/>
    </MultiDataTrigger.EnterActions>
    <MultiDataTrigger.ExitActions>
        <RemoveStoryboard BeginStoryboardName="BeginStoryboard_TurnToUnselectedStyle1"/>
    </MultiDataTrigger.ExitActions>
</MultiDataTrigger>
于 2013-03-30T11:20:57.387 回答