In my WPF project I need to animate several properties with the same value. So my idea was to create a custom, private dependency property to which the animation will be applied. Unfortunately this doesn’t seem to work. DependencyPropertyDescriptor.FromProperty() always returns null for this property. Here is the code:
public partial class PedestrianVisual : UserControl {
private static readonly DependencyProperty CurrentInaccuracyRadiusProperty =
DependencyProperty.Register("CurrentInaccuracyRadius", typeof(double), typeof(PedestrianVisual));
private double CurrentInaccuracyRadius {
get { return (double)GetValue(CurrentInaccuracyRadiusProperty); }
set { SetValue(CurrentInaccuracyRadiusProperty, value); }
}
public PedestrianVisual() {
InitializeComponent();
// This returns "null" all the time.
DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(
CurrentInaccuracyRadiusProperty, typeof(PedestrianVisual));
dpd.AddValueChanged(this, (s, e) => {
UpdateInaccuracyCircle((double)GetValue(CurrentInaccuracyRadiusProperty));
});
}
private void UpdateInaccuracyCircle(double curRadius) {
// do something here
}
}
Is there any other way to create a private dependency property?
I don’t understand why you would do it that way, i did not encounter any problems when attaching the callback in the declaration, e.g. something like this:
(
UpdateInaccuracyCirclemethod should be static in this case)If you want to stick with the instance method: