c# - ICustomTypeDescriptor with display -
hi guys implementing interface icustomtypedescriptor , binding wpf grid. having issues result, expecting single column "random" getting totally different. appreciated. andy
/// <summary> /// property descriptor test result row wrapper /// </summary> public class testresultpropertydescriptor : propertydescriptor { //- properties -------------------------------------------------------------------------------------------------------------- #region properties /// <summary> /// component type /// </summary> public override type componenttype { { return typeof(dictionary<string, testresultvalue>); } } /// <summary> /// gets whether read /// </summary> public override bool isreadonly { { return false; } } /// <summary> /// gets property type /// </summary> public override type propertytype { { return typeof(string); } } #endregion properties //- constructor ------------------------------------------------------------------------------------------------------------- #region constructor /// <summary> /// constructor /// </summary> public testresultpropertydescriptor(string key) : base(key, null) { } #endregion constructor //- methods ----------------------------------------------------------------------------------------------------------------- #region methods /// <summary> /// can reset value /// </summary> public override bool canresetvalue(object component) { return true; } /// <summary> /// gets value /// </summary> public override object getvalue(object component) { return ((dictionary<string, testresultvalue>)component)[base.name].value; } /// <summary> /// resets value /// </summary> public override void resetvalue(object component) { ((dictionary<string, testresultvalue>)component)[base.name].value = string.empty; } /// <summary> /// sets value /// </summary> public override void setvalue(object component, object value) { ((dictionary<string, testresultvalue>)component)[base.name].value = value.tostring(); } /// <summary> /// gets whether value should serialized /// </summary> public override bool shouldserializevalue(object component) { return false; } #endregion methods //--------------------------------------------------------------------------------------------------------------------------- } /// <summary> /// class manage test result row data functions /// </summary> public class testresultrowwrapper : dictionary<string, testresultvalue>, icustomtypedescriptor { //- methods ----------------------------------------------------------------------------------------------------------------- #region methods /// <summary> /// gets attributes object /// </summary> attributecollection icustomtypedescriptor.getattributes() { return new attributecollection(null); } /// <summary> /// gets class name /// </summary> string icustomtypedescriptor.getclassname() { return null; } /// <summary> /// gets component name /// </summary> string icustomtypedescriptor.getcomponentname() { return null; } /// <summary> /// gets type converter /// </summary> typeconverter icustomtypedescriptor.getconverter() { return null; } /// <summary> /// gets default event /// </summary> /// <returns></returns> eventdescriptor icustomtypedescriptor.getdefaultevent() { return null; } /// <summary> /// gets default property /// </summary> propertydescriptor icustomtypedescriptor.getdefaultproperty() { return null; } /// <summary> /// gets editor /// </summary> object icustomtypedescriptor.geteditor(type editorbasetype) { return null; } /// <summary> /// gets events /// </summary> eventdescriptorcollection icustomtypedescriptor.getevents(attribute[] attributes) { return new eventdescriptorcollection(null); } /// <summary> /// gets events /// </summary> eventdescriptorcollection icustomtypedescriptor.getevents() { return new eventdescriptorcollection(null); } /// <summary> /// gets properties /// </summary> propertydescriptorcollection icustomtypedescriptor.getproperties(attribute[] attributes) { list<testresultpropertydescriptor> properties = new list<testresultpropertydescriptor>(); //add property descriptors each entry in dictionary foreach (string key in this.keys) { properties.add(new testresultpropertydescriptor(key)); } //get properties belonging class //propertydescriptorcollection pdc = typedescriptor.getproperties(this.gettype(), attributes); //foreach (propertydescriptor opropertydescriptor in pdc) //{ // properties.add(opropertydescriptor); //} return new propertydescriptorcollection(properties.toarray()); } /// <summary> /// gets properties /// </summary> propertydescriptorcollection icustomtypedescriptor.getproperties() { list<testresultpropertydescriptor> properties = new list<testresultpropertydescriptor>(); foreach (string key in this.keys) { properties.add(new testresultpropertydescriptor(key)); } return new propertydescriptorcollection(properties.toarray()); } /// <summary> /// gets property owner /// </summary> object icustomtypedescriptor.getpropertyowner(propertydescriptor pd) { return this; } #endregion methods //--------------------------------------------------------------------------------------------------------------------------- }`public class testresultvalue { private object _value; public object value { { return _value; } set { _value = value; } } }`
this how using it...
var items = new observablecollection<testresultrowwrapper>(); var row = new testresultrowwrapper(); row.add("random", new testresultvalue() { value=1.1}); items.add(row); datagrid1.itemssource = items;
Comments
Post a Comment