c# - xceed wpf propertygrid collection select -
i'm new in wpf , may it's stupid question, but...) have custom properties class visualased xceed wpf propertygrid
public class shopproperties { private readonly observablecollection<string> _cars = new observablecollection<string>(); [category(@"carsshop")] [displayname(@"carscollection")] public observablecollection<string> carscollection { {return _cars;}} [browsable(false)] private string selectedcar {get; set;} }
what simplest , finest propertygrid editor(or custom editor) need use assign selectedcar element carscollection?
after search , reading http://wpftoolkit.codeplex.com/wikipage?title=propertygrid&referringtitle=documentation think minimum 2 ways in case.
1. customise xctk:collectioncontrol
, edit xaml.
<xctk:propertygrid name="_generalpropertygrid" dockpanel.dock="top" showsearchbox="false" showsortoptions="false" showtitle="false" namecolumnwidth="120" borderthickness="0"> <xctk:propertygrid.editordefinitions> <xctk:editortemplatedefinition targetproperties="carscollection"> <xctk:editortemplatedefinition.editingtemplate> <datatemplate> <xctk:collectioncontrol selecteditem="{binding path=selectedcar}"/> </datatemplate> </xctk:editortemplatedefinition.editingtemplate> </xctk:editortemplatedefinition> </xctk:propertygrid.editordefinitions> </xctk:propertygrid>
2. create own usercontrol
implements itypeeditor
see datails in http://wpftoolkit.codeplex.com/wikipage?title=propertygrid&referringtitle=documentation select combobox
. choose way.
<usercontrol x:class="proj_namespace.carselector" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" x:name="carselector" d:designheight="25" d:designwidth="200"> <grid> <combobox itemssource="{binding value, elementname=carselector}" selectionchanged="selector_onselectionchanged"/> </grid> </usercontrol>
and class code behind:
public partial class carselector : itypeeditor { public carselector() { initializecomponent(); } public static readonly dependencyproperty valueproperty = dependencyproperty.register("value", typeof(observablecollection<string>), typeof(carselector), new frameworkpropertymetadata(null, frameworkpropertymetadataoptions.bindstwowaybydefault)); public string value { { return (string)getvalue(valueproperty); } set { setvalue(valueproperty, value); } } public frameworkelement resolveeditor(propertyitem propertyitem) { var binding = new binding("value"); binding.source = propertyitem; binding.mode = propertyitem.isreadonly ? bindingmode.oneway : bindingmode.twoway; bindingoperations.setbinding(this, valueproperty, binding); return this; } private void selector_onselectionchanged(object sender, selectionchangedeventargs e) { if (sender != null) mainwindow.instance._properties.selectedcar = (sender combobox).selecteditem string; } }
and add custom editor line above property
[editor(typeof(carselector), typeof(carselector))] public observablecollection<string> carscollection { { return _securities; } }
Comments
Post a Comment