Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 通知xaml是否调用依赖项属性的SetValue()_Wpf_Mvvm_Binding_Dependency Properties_Setter - Fatal编程技术网

Wpf 通知xaml是否调用依赖项属性的SetValue()

Wpf 通知xaml是否调用依赖项属性的SetValue(),wpf,mvvm,binding,dependency-properties,setter,Wpf,Mvvm,Binding,Dependency Properties,Setter,我想在列表框中的用户控件中绘制线条。行数是一个依赖项属性,通过Xaml样式设置。如果属性已更改,我想画线。但如果属性被xaml更改,则不会调用setter。Xaml调用SetValue()本身。但是我需要知道,当这个属性被更改为调用我的函数来绘制线条时。如果在构造函数中调用此函数,则该属性尚未绑定。有人能帮我吗。您可以将属性更改回调添加到您的DependencyProperty声明中 public static readonly DependencyProperty LineCountPrope

我想在列表框中的用户控件中绘制线条。行数是一个依赖项属性,通过Xaml样式设置。如果属性已更改,我想画线。但如果属性被xaml更改,则不会调用setter。Xaml调用SetValue()本身。但是我需要知道,当这个属性被更改为调用我的函数来绘制线条时。如果在构造函数中调用此函数,则该属性尚未绑定。有人能帮我吗。

您可以将
属性更改
回调添加到您的
DependencyProperty
声明中

public static readonly DependencyProperty LineCountProperty = DependencyProperty.Register(
    "LineCount",
    typeof(int),
    typeof(Window),
    new FrameworkPropertyMetadata(
        0,
        new PropertyChangedCallback(OnLineCountChanged)
    )
);


private static void OnLineCountChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
   //Here you call you function on `d` by typecasting it into your class
}

您可以将
PropertyChanged
回调添加到
dependencProperty
声明中,如

public static readonly DependencyProperty LineCountProperty = DependencyProperty.Register(
    "LineCount",
    typeof(int),
    typeof(Window),
    new FrameworkPropertyMetadata(
        0,
        new PropertyChangedCallback(OnLineCountChanged)
    )
);


private static void OnLineCountChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
   //Here you call you function on `d` by typecasting it into your class
}

哇,它的工作,非常感谢你,我搜索了这么久,但找不到一个解决方案。现在我很高兴:)哇,它的工作,非常感谢你,我搜索了这么久,但找不到一个解决方案。现在我很高兴:)