WPF Designer has bug with parsing generic control with overrided property
Posted
by Ivan Laktyunkin
on Stack Overflow
See other posts from Stack Overflow
or by Ivan Laktyunkin
Published on 2008-12-18T10:33:21Z
Indexed on
2010/04/26
8:53 UTC
Read the original article
Hit count: 423
I've created a generic lookless control with 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've made a control derived from it and overrided Value property:
public class TestControl : TestControlBase<int>
{
public override int Value
{
get
{
return base.Value;
}
set
{
base.Value = value;
}
}
}
So I use it in a Window XAML:
<TestControls:TestControl />
When I open window in designer all is OK, but when I put mouse cursor to this line, or to this control in designer I receive 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 know this problem? Please explain :) I have no ideas except that WPF Designer doesn't like generics. If I replace generics by Object
all is OK.
© Stack Overflow or respective owner