如何将XAML触发器调用为XAML样式?

时间:2009-07-07 13:27:47

标签: wpf xaml animation triggers

此样式根据ViewModel属性的更改正确地淡入或淡出我的工具栏:

<Style x:Key="PageToolBarStyle" TargetType="Border">
    <Style.Triggers>
        <DataTrigger Binding="{Binding PageToolBarVisible}" Value="true">

            <DataTrigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            Storyboard.TargetProperty="Opacity"
                            From="0.0" 
                            To="1.0" 
                            Duration="0:0:2"/>
                    </Storyboard>
                </BeginStoryboard>
            </DataTrigger.EnterActions>

            <DataTrigger.ExitActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            Storyboard.TargetProperty="Opacity"
                            From="1.0" 
                            To="0.0" 
                            Duration="0:0:2"/>
                    </Storyboard>
                </BeginStoryboard>
            </DataTrigger.ExitActions>

        </DataTrigger>

        <Trigger Property="Opacity" Value="0">
            <Setter Property="Visibility" Value="Collapsed"/>
        </Trigger>

    </Style.Triggers>
</Style>

但是,当应用程序加载时,工具栏的状态(淡出或淡出)不同步与ViewModel属性的值(true或false) 。所以我想在加载窗口时强制执行此样式,执行此操作的语法是什么,这里是我想要做的伪代码:

<Window.Triggers>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
        <EventTrigger.Actions>

           <!-- PSEUDO-CODE: -->
            <ExecuteTriggerStyle StyleToExecute="{StaticResource PageToolBarStyle}"/>

        </EventTrigger.Actions>
    </EventTrigger>
</Window.Triggers>

0 个答案:

没有答案