我有一个类层次结构,如下所示,绑定到VisibleRange属性是在设计器中抛出.
鉴于此处的类层次结构:
// 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 { }
和设计师(XAML)在这里:
<local:DateTimeAxis Style="{StaticResource XAxisStyle}" VisibleRange="{Binding ElementName=priceChart,Path=XAxis.VisibleRange,Mode=TwoWay}"/>
我得到这个例外:
A ‘Binding’ cannot be set on the ‘VisibleRange’ property of type ‘DateTimeAxis’. A ‘Binding’ can only be set on a DependencyProperty of a DependencyObject.
派生类DateTimeAxis公开VisibleRange属性,该属性被new关键字覆盖.我不能将通用类型参数添加到基本AxisBase类,我还需要访问这两个类中的属性.所以,我想知道给定这些约束,如果有人有任何建议如何更好地避免设计师异常?