WPF:使用动画更改GridViewColumn的宽度

时间:2019-02-20 18:45:30

标签: wpf animation storyboard

我有ListView我想根据属性更改使用GridViewColumn更改其animation的宽度。

这就是我尝试过的(属性实现INotifyPropertyChanged并更改了它的值):

<ListView>
<ListView.View>
<GridView>
    <GridViewColumn Header="Select" Width="0">                                         
        <GridViewColumn.CellTemplate>
            <DataTemplate>
                <DataTemplate.Resources>
                    <DataTrigger x:Key="ee" Binding="{Binding Path=IsTrue}" Value="True">
                        <DataTrigger.EnterActions>
                            <StopStoryboard BeginStoryboardName="EndAnimation"/>
                            <BeginStoryboard Name="NewAnimation">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Width" 
                                                     From="0"
                                                     To="50" 
                                                     DecelerationRatio=".9" 
                                                     Duration="0:0:0.3" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                    </DataTrigger>
                    <DataTrigger x:Key="ee1" Binding="{Binding Path=IsTrue}" Value="False">
                        <DataTrigger.EnterActions>
                            <StopStoryboard BeginStoryboardName="NewAnimation"/>
                            <BeginStoryboard Name="EndAnimation">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Width" 
                                                     From="50"
                                                     To="0" 
                                                     DecelerationRatio=".9" 
                                                     Duration="0:0:0.3" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                    </DataTrigger>
                </DataTemplate.Resources>
            </DataTemplate>
        </GridViewColumn.CellTemplate>
    </GridViewColumn>
</GridView>
</ListView.View>
</ListView>

因此,尽管property当前发生了变化,但我看不到宽度发生了变化。

有什么建议吗?

0 个答案:

没有答案