I have a class hierarchy as follows, and the binding to the VisibleRange property is thrown into the constructor.
Given the class hierarchy:
// Base class public abstract class AxisBase : ContentControl, IAxis { public static readonly DependencyProperty VisibleRangeProperty = DependencyProperty.Register( "VisibleRange", typeof(IRange), typeof(AxisBase), new PropertyMetadata(default(IRange), OnVisibleRangeChanged)); public IRange VisibleRange { get { return (IRange)GetValue(VisibleRangeProperty); } set { SetValue(VisibleRangeProperty, value); } } } // Derived class public class DateTimeAxis : AxisBase { public new IRange<DateTime> VisibleRange { get { return (IRange<DateTime>)GetValue(VisibleRangeProperty); } set { SetValue(VisibleRangeProperty, value); } } } // And interface definitions public interface IRange<T> : IRange { }
And the constructor (XAML) is here:
<local:DateTimeAxis Style="{StaticResource XAxisStyle}" VisibleRange="{Binding ElementName=priceChart, Path=XAxis.VisibleRange, Mode=TwoWay}"/>
I get this exception:
Binding cannot be set in the VisibleRange property of type DateTimeAxis. Binding can only be set in the DependencyProperty of a DependencyObject.
The derived DateTimeAxis
class represents the VisibleRange property, which is overridden by the new
keyword. I cannot add a generic typeparam to the AxisBase base class, and I also need to access the property in both classes. So, I am wondering, given these limitations, if anyone has any suggestions on how to do this better to avoid designer exceptions?
source share