Wpf 通知xaml是否调用依赖项属性的SetValue()
我想在列表框中的用户控件中绘制线条。行数是一个依赖项属性,通过Xaml样式设置。如果属性已更改,我想画线。但如果属性被xaml更改,则不会调用setter。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
属性更改
回调添加到您的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
}
哇,它的工作,非常感谢你,我搜索了这么久,但找不到一个解决方案。现在我很高兴:)哇,它的工作,非常感谢你,我搜索了这么久,但找不到一个解决方案。现在我很高兴:)