This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, I trying to use WPF PropertyGrid control as editing control for all public properties of a object. After binding the SelectedObject of the PropertyGrid control to the object, I still need a way to define the Node names (i.e. the "Property" display names that are displayed automatically) in declarative XAML explicitly. Is there a way to do that? Something that will allow to add XAML code like: <ms:PropertyGridNode Binding="{Binding City}" Header="City Field Header Text"></ms:PropertyGridNode> where City is one public property of the bound object in PropertyGrid.SelectedObject. This kind of code will further allow to get the display name (i.e. "City Field Header Text") for the City property from a static resource file. I also do NOT want to use the DisplayName attribute - with support for globalization as specified at http://www.codeproject.com/KB/miscctrl/globalizedpropertygrid.aspx Thanks and Regards, Chetna
|
|
|
That isn't directly supported within the property grid, but could be achieved by customising the property name cell template. My suggested plan of attach would be: * Define a DataTemplate for the property name cell. This DataTemplate will receive a PropertyGridRow, which has a Node property that contains the property info. * In your DataTemplate, use Node or Node.Name to perform a lookup into a list of display names, e.g. using a value converter and a set of resources, or an attached property on the grid, or wherever you want to store the name overrides. * In your property grid declaration, set PropertyNameTemplate="{StaticResource MyCustomTemplate}". Note that your DataTemplate is a low-level override and therefore needs to handle things like expansion and selection. Here is a starter template. The section you would need to change is highlighted: <ms:LevelToIndentConverter x:Key="LevelToIndentConverter" /> <DataTemplate x:Key="MyCustomTemplate"> You can also refer to the Source / Styles directory under the installation folder for customised examples. |
|
|
Hi Ivan, Thanks so much. The solution mentioned by you works - with adding a converter for getting the display name from resource file. There is still one problem. Now the Sort and Filter - do not work - as they get applied against node.Name and node.Human name. I looked at the 02_AddingSortingAndFiltering.xaml sample. But that would not work - even with adding read from resource file - as now after applying a PropertyName template - there is no way to get the value displayed there to match for applying filters using CollectionView or for use in SortDescription. Thanks and Regards, Chetna
|
|
|
You will need to use a custom sort -- see http://www.mindscape.co.nz/blog/index.php/2008/06/19/custom-sorting-wpf-collection-views-and-the-wpf-property-grid/ for info. Your custom sort and filter delegates should be able to access the same logic and resources as the property name template, though you will probably need to pass in any resources explicitly. If this isn't enough to get this working for you, could you post a more complete sample showing how you're representing, organising and loading the custom name info, and I'll see if I can work up a sample for you. |
|