我已经定义了一个依赖属性格式如下:依赖属性绑定未更新
public static readonly DependencyProperty AnimateColumnWidthProperty =
DependencyProperty.Register("AnimateColumnWidthProperty", typeof(double), typeof(MainWindow), new PropertyMetadata(0.0));
public double AnimateColumnWidth
{
get { return (double)GetValue(AnimateColumnWidthProperty); }
set { SetValue(AnimateColumnWidthProperty, value); }
}
当我的应用程序开始我做这个....
private void Window_Loaded(object sender, RoutedEventArgs e)
{
AnimateColumnWidth = Properties.Settings.Default.ProductInfoWidthExpanded;
}
...这应该初始化值到它的初始值 - 在这种情况下是400.
然后我在我的用户界面中绑定了一列网格到这个属性...
<ColumnDefinition
Name="ProductInfo"
Width="{Binding Path=AnimateColumnWidth,
Converter={StaticResource doubleToGridLength},
Mode=TwoWay}" />
据我所知,由于列宽被绑定到这个属性,每当我更新属性的列宽也应该更新。
我做错了什么,因为当我更改属性时宽度不会更新?我也试图通过动画来更新它,这也不起作用。此外,在AnimateColumnWidth属性的getter上设置的断点永远不会被打 - 这意味着什么都没有试图检索属性。
(这没有工作,所以我清楚的地方有一些破!!)
脚注:
转换在我的应用程序的根命名空间中定义的值(我相信,如果它不可能WPF会抱怨找到它)。
[ValueConversion(typeof(Double), typeof(GridLength))]
public class DoubleToGridLength : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return new GridLength((double)value);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((GridLength)value).Value;
}
}
+1用于链接到msdn调试绑定链接 –
绑定提示做了诀窍。网格的datacontext尚未设置。 – Remotec