样式中带有绑定的多个DataTriggers

时间:2016-05-16 18:51:36

标签: c# wpf data-binding triggers

我有一个带有一些动画的网格:

<Grid.Style>
    <Style>
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=PanelShown}" Value="True">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ThicknessAnimation Storyboard.TargetProperty="Margin" Duration="0:0:0.2" To="0,-350,0,350" />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <DataTrigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ThicknessAnimation Storyboard.TargetProperty="Margin" Duration="0:0:0.2" To="0,0,0,0" />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.ExitActions>
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=ReportErrorPanelShown}" Value="True">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ThicknessAnimation Storyboard.TargetProperty="Margin" Duration="0:0:0.2" To="-750,0,750,0" />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <DataTrigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ThicknessAnimation Storyboard.TargetProperty="Margin" Duration="0:0:0.2" To="0,0,0,0" />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.ExitActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Grid.Style>

但是这段代码不能正常工作。如果我删除了其中一个数据触发器,但是如果我只使用这个代码,那么只有第二个dataTrigger会在Binding属性发生变化时触发。如何使用两个(甚至更多)DataTriggers和Bindings?

0 个答案:

没有答案