We have a custom panel class that animates its children via an internal DoubleAnimation object. However, we want to expose the animation's Duration dependency property as a public property of our panel so the user can change it in their XAML when using our panel. But we don't want to expose any other part of the animation object, just the duration.
The first thing that keeps getting suggested to me is to use the PropertyChanged notification, but that would only work for the setter, not the getter. We also can't simply create a .NET property since XAML bypasses the .NET property altogether.
A co-worker of mine had a clever idea... use two-way data binding between the outer property and the internal object's property, which actually seems like a pretty neat solution. However, data binding aside, is there another/a better way to do this... exposing an internal object's dependency property via it's containing object's public interface?
Updated:
Looks like two-way DataBinding was the way to go. (Thanks @Jeff!) To that end, here's what I found to be the best way to set up the outer DP so it's a perfect match--metadata, defaults and all--for the inner object's DP! Then use Jeff's binding 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));