【问题标题】:prevent animation from occurring when initially binding防止初始绑定时出现动画
【发布时间】:2012-05-05 06:05:47
【问题描述】:

我有第二个堆栈面板,看起来像一个抽屉,如下所示

 ______               ______ _____
|      |             |      |     |
| main |     ->      | main | 2nd |
|______|             |______|_____|
                              -->

我有抽屉的展开和折叠动画。它们绑定到我在代码中更新的布尔值。

一切正常,除了当我最初启动我的应用程序时,折叠动画被触发,因为初始值为 false。有没有办法绑定某些东西而不触发绑定?


这是我的 xaml 中的样子,我在其中使用绑定到我的代码中的布尔值的 DataTrigger:

        <StackPanel x:Name="expandMe" Width="0" Orientation="Vertical" >
            <StackPanel.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ExpandBoolean}" Value="False">
                            .......

【问题讨论】:

  • 将init值设置为true有问题吗?
  • 好吧,这将在开始时执行展开动画而不是折叠动画。理想情况下,我希望它开始关闭(假),而不执行绑定到它的动画为假
  • 您是否尝试过加载控件后添加动画?这可能会奏效
  • 看起来像一个有趣的谜题,你能发布你的代码吗?我会玩它并让它工作(希望如此)
  • 发布太多了,但我发布了我绑定到数据触发器的 xaml 部分。不确定我是否真的可以“推迟”绑定

标签: wpf animation binding expand collapse


【解决方案1】:

我没有在您的样式中看到 Setter,以确保 StackPanel 加载已折叠。我想这样就可以了。

<StackPanel x:Name="expandMe" Width="0" Orientation="Vertical" >
        <StackPanel.Style>
            <Style>
                <Setter Property="StackPanel.Visibility" Value "Collapsed"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ExpandBoolean}" Value="False">

【讨论】:

  • 甜,做到了。我只需要在“True”DataTrigger 中添加另一个 Setter,将 Visibility 设置回 Visible。谢谢!
猜你喜欢
  • 2016-03-24
  • 2013-12-10
  • 1970-01-01
  • 1970-01-01
  • 2017-04-28
  • 1970-01-01
  • 2013-11-02
  • 2011-04-22
  • 2019-05-16
相关资源
最近更新 更多