【发布时间】: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