Rem*_*tec 2 .net c# wpf xaml dependency-properties
我已经定义了一个依赖项属性如下:
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); }
}
Run Code Online (Sandbox Code Playgroud)
当我的应用程序启动时,我这样做....
private void Window_Loaded(object sender, RoutedEventArgs e)
{
AnimateColumnWidth = Properties.Settings.Default.ProductInfoWidthExpanded;
}
Run Code Online (Sandbox Code Playgroud)
...应将值初始化为其起始值 - 在本例中为400.
然后我在我的UI中将一列网格绑定到此属性...
<ColumnDefinition
Name="ProductInfo"
Width="{Binding Path=AnimateColumnWidth,
Converter={StaticResource doubleToGridLength},
Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)
据我了解,由于列宽已绑定到此属性,每当我更新属性时,列宽也应更新.
当我更改属性时,宽度不会更新,我做错了什么?我也试图通过动画更新它,也不起作用.此外,在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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4214 次 |
| 最近记录: |