
Hi,
We have created propertyGrid with customFactory like in example.
I have two questions about customization property grid.
1. In example are used only string types. Is it possible to use another type and if yes, can you please point, what I am doing here wrong. Here I define my customFactory:
protected override IList<IPropertyDataAccessor> GetProperties(object value, DataFactoryOptions options)
{
IList<IPropertyDataAccessor> dataAccessors;
var uc = value as UserControlViewModel;
if (uc != null)
{
// Create a list of property data accessor results
dataAccessors = new List<IPropertyDataAccessor>();
dataAccessors.Add(new CustomPropertyDataAccessor<UserControlViewModel, string>(uc, o => o.ControlName, "Control Name", null, "CategoryName", "Description"));
dataAccessors.Add(new CustomPropertyDataAccessor<UserControlViewModel, int>(uc, o => o.ZIndex, "Z index", null, "CategoryName","CategoryName",));
}
else
{
// Fall back to using the base method's results for nested objects
dataAccessors = base.GetProperties(value, options);
}
return dataAccessors;
}
Here the problem is that when I try to modify ZIndex value in propertyGrid, I get InvalidCastException in setter in CustomPropertyDataAccessor:
protected override object ValueInternal
{
get
{
return propGetter(target);
}
set
{
propSetter(target, (TValue)value);
}
}
And it works perfectly with string variables like ControlName.
My ZIndex is :
public override int ZIndex
{
get { return _zIndex; }
set
{
_zIndex = value;
RaisePropertyChanged();
}
}
2. We would like to set from code readOnly states like in example Selective ReadOnly. It's not very clear to me, where should I ovveride IPropertyDataAccessor CreatePropertyDataAccessor. My customFactory looks like:
public class CustomFactory : CustomBaseFactory
{
protected override IList<IPropertyDataAccessor> GetProperties(object value, DataFactoryOptions options)
{
}
}
And CustomBaseFactory overrides IPropertyDataAccessor. But in debug I saw that code never comes to overriden IPropertyDataAccessor method. Where can I be wrong here?
Thank you.