How to make add a fade-in/fade-out animation based on ViewModel property value?

前端 未结 1 1637
死守一世寂寞
死守一世寂寞 2021-01-13 22:12

I have a ViewModel which exposes the string property PageToolBarVisible which can be true or false:

相关标签:
1条回答
  • 2021-01-13 22:33

    You can put the BeginStoryboard inside your DataTrigger.EnterActions

    <DataTrigger Binding="{Binding PageToolBarVisible}" Value="false">
        <DataTrigger.EnterActions>
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation
                    Storyboard.TargetName="PageToolBar"
                    Storyboard.TargetProperty="(TextBlock.Opacity)"
                    From="0.0" To="1.0" Duration="0:0:3"/>
                </Storyboard>
            </BeginStoryboard>
        </DataTrigger.EnterActions>
    
        <DataTrigger.ExitActions>
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation
                        Storyboard.TargetName="PageToolBar"
                        Storyboard.TargetProperty="(TextBlock.Opacity)"
                        From="1.0" To="0.0" Duration="0:0:3"/>
                </Storyboard>
            </BeginStoryboard>
        </DataTrigger.ExitActions>
    </DataTrigger>
    
    0 讨论(0)
提交回复
热议问题