【问题标题】:Grid Hide/Show animation网格隐藏/显示动画
【发布时间】:2014-11-10 10:19:10
【问题描述】:

我有一些用户控件,它是具有透明背景的网格,除此之外还有另一个网格,它假设在触发触发器时会改变其宽度(最终它将是一个输入/输出动画)。目的是简单地使用与可见性不同的东西,它会立即隐藏整个控件而没有任何动画这是它所基于的属性:

    public static readonly DependencyProperty IsOpenedProperty = DependencyProperty.Register ("IsOpened", typeof (Boolean), typeof (SidePanel), new PropertyMetadata (false));

    public bool IsOpened {
        get {
            if (GetValue (IsOpenedProperty) != null)
                return (bool)GetValue (IsOpenedProperty);
            else
                return false;
        }
        set {
            SetValue (IsOpenedProperty, value);
            Console.WriteLine(value);
        }
    }

还有网格本身:

<Grid>
    <Grid.Style>
        <Style TargetType="{x:Type Grid}">
            <Setter Property="Width" Value="50"/>
            <Setter Property="Background" Value="Gray"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsOpened}" Value="True">
                    <Setter Property="Width" Value="350"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsOpened}" Value="False">
                    <Setter Property="Width" Value="0"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Grid.Style>

    <TextBlock Text="{Binding ElementName=Side, Path=Width}"/>
</Grid>

控制台给了我正确的输出,但触发器根本不触发。

刚刚检查了一件事,当我为 x:Null 值设置触发器时,它一直被触发,怎么可能 Get 不应该在这里返回 null 值?

【问题讨论】:

    标签: wpf xaml animation triggers grid


    【解决方案1】:

    好吧,我刚刚在这里放弃了依赖属性,创建了私有变量来保存值并使用 INotifyPropertyChanged 接口实现添加了数据上下文,现在它可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-25
      • 2016-02-02
      • 1970-01-01
      • 2018-12-03
      • 2016-06-12
      • 2010-11-04
      相关资源
      最近更新 更多