仮想プロパティを持つ一般的なルックレス コントロールを作成しました。
public abstract class TestControlBase<TValue> : Control
{
public static readonly DependencyProperty ValueProperty;
static TestControlBase()
{
ValueProperty = DependencyProperty.Register("Value", typeof(TValue),
typeof(TestControlBase<TValue>));
}
protected TestControlBase()
{
Focusable = false;
Value = default(TValue);
}
public virtual TValue Value
{
get
{
return (TValue)GetValue(ValueProperty);
}
set
{
SetValue(ValueProperty, value);
}
}
}
次に、それから派生したコントロールを作成し、Value プロパティをオーバーライドしました。
public class TestControl : TestControlBase<int>
{
public override int Value
{
get
{
return base.Value;
}
set
{
base.Value = value;
}
}
}
したがって、ウィンドウ XAML で使用します。
<TestControls:TestControl />
デザイナーでウィンドウを開くとすべて問題ありませんが、マウスカーソルをこの行またはデザイナーのこのコントロールに置くと、例外が発生します。
Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
Ambiguous match found.
at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetProperty(String name)
at MS.Internal.ComponentModel.DependencyPropertyKind.get_IsDirect()
at MS.Internal.ComponentModel.DependencyPropertyKind.get_IsAttached()
at MS.Internal.ComponentModel.APCustomTypeDescriptor.GetProperties(Attribute[] attributes)
at MS.Internal.ComponentModel.APCustomTypeDescriptor.GetProperties()
at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultExtendedTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()
at System.ComponentModel.TypeDescriptor.GetPropertiesImpl(Object component, Attribute[] attributes, Boolean noCustomTypeDesc, Boolean noAttributes)
at System.ComponentModel.TypeDescriptor.GetProperties(Object component)
at MS.Internal.Model.ModelPropertyCollectionImpl.GetProperties(String propertyNameHint)
at MS.Internal.Model.ModelPropertyCollectionImpl.<GetEnumerator>d__0.MoveNext()
at MS.Internal.Designer.PropertyEditing.Model.ModelPropertyMerger.<GetFirstProperties>d__0.MoveNext()
at MS.Internal.Designer.PropertyEditing.PropertyInspector.UpdateCategories(Selection selection)
at MS.Internal.Designer.PropertyEditing.PropertyInspector.OnSelectionChangedIdle()
誰がこの問題を知っていますか? 説明してください:) WPFデザイナーがジェネリックを好まないことを除いて、私には考えがありません。Object
ジェネリックをすべて置き換えればOKです。