WPF Designer has error parsing common control with overridden property

I created a generic useless control with a virtual property:

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);
        }
    }
}

Then I created a managed item and overrided the Value property:

public class TestControl : TestControlBase<int>
{
    public override int Value
    {
        get
        {
            return base.Value;
        }
        set
        {
            base.Value = value;
        }
    }
}

Therefore, I use it in Window XAML:

    <TestControls:TestControl />

When I open a window in the designer, everything is fine, but when I place the mouse cursor on this line or on this control in the constructor, I get an exception:

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()

Who knows this problem? Please explain :) I have no ideas, except that WPF Designer does not like generics. If you replace generics with Object, everything will be OK.

+3
source share
3 answers

Ivan

, , . , , , . googleing , . , , xaml. , .

+2

, . . WF- .

, , , . , . , generic (< > ), .

, :)

+1

, () ...
, .
unset. , .

+1

All Articles