We have our own panel class that animates its children through an internal DoubleAnimation object. However, we want to show the animation duration dependency property as a public property of our panel so that the user can change it in their XAML when using our panel. But we don’t want to reveal any other part of the animation object, just the duration.
The first thing that tells me is to use the PropertyChanged notification, but this will only work for the installer and not for the recipient. We also cannot just create a .NET property, because XAML generally bypasses the .NET property.
My colleague had a clever idea ... to use two-way data binding between the external property and the internal property of the object, which actually seems like a pretty neat solution. However, data binding to the side, is there another / better way to do this ... exposing the internal dependency property of an object through it containing the public interface of the object?
Updated:
Two-way DataBinding seems to be the way to go. (Thanks @Jeff!) For this purpose, here I have found the best way to configure the external DP so that it perfectly matches - metadata, default values and all - for the internal DP object! Then use the Jeff-bound trick and you're done!
public Duration Duration {
get { return (Duration)GetValue(DurationProperty); }
set { SetValue(DurationProperty, value); }
}
public static readonly DependencyProperty DurationProperty = DoubleAnimation.DurationProperty.AddOwner(
typeof(SlideContentPanel));
source
share