How can I make a XAML Trigger call a XAML Style?

青春壹個敷衍的年華 提交于 2020-01-05 03:50:06

问题


This style correctly fades my toolbar in or out based on the changing of a ViewModel Property:

<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>

However, when the application loads the status of the toolbar (faded out or in) is not in sync with the value of the ViewModel property (true or false). So I want to force this style to be executed upon loading the window, what is the syntax to do this, here is pseudo code of what I want to do:

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

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

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

来源:https://stackoverflow.com/questions/1092330/how-can-i-make-a-xaml-trigger-call-a-xaml-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!