WPF XAML Grid Visibility Trigger

后端 未结 1 590
别那么骄傲
别那么骄傲 2021-02-14 07:32

I have a status message located on the first row of my grid and I want it to slide in and out when the visibility changes.
The first visibility trigger works great and slide

相关标签:
1条回答
  • 2021-02-14 08:01

    You should remove the Visibility binding in your grid and use a DataTrigger that binds to the StatusMessageVisibility property. If you bind the grid's visibility then once it's collapsed it's collapsed and you won't be able to see the animation.

    Also, instead of having two data triggers with EnterActions, use a single data trigger that also has an ExitAction for the collapsed state:

    <Grid Grid.Row="0" Height="55">
        <Grid.Style>
            <Style TargetType="Grid">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding StatusMessageVisibility}" Value="Visible">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="55" Duration="0:0:.1" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Height" From="55" To="0" Duration="0:0:0.1" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.ExitActions>
                    </DataTrigger>               
                </Style.Triggers>
            </Style>
        </Grid.Style>
        <TextBlock Text="Hi There" />
    </Grid>
    
    0 讨论(0)
提交回复
热议问题