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
|
Is it possible to create "Custom Label for a Property" something like <DataTemplate x:Key='FeetAndInchesLabel'> <ms:PropertyGrid.Labels> |
|
|
This is currently only possible by retemplating the grid and creating your own data template for the left hand cell. See the thread at http://www.mindscape.co.nz/forums/Thread.aspx?PostID=1923 (and the linked thread from there) for some guidance -- once you have retemplated the grid you can create your own template or template selector for the left hand column. We will add this one to the wishlist though. |
|
|
We have now added the ability to create your own templates for the left hand side via the PropertyGrid.PropertyNameTemplate property. This will be in the next nightly, available from about 1800 GMT. One thing to note is that a custom template must supply EVERYTHING it wants to see in the left hand side, specifically including the "expand" button. This is so that custom templates have full flexibility to replace everything, including the expansion UI. Here is a rather frivolous sample: <ms:LevelToIndentConverter x:Key="LevelToIndentConverter" /> Key things to note are the triggers which hide the expand button when there are no children, and the toggle button definition which handles layout and functionality of the expand button. |
|
|
Thats great if I need modify the look of all labels. How can I override Node.HumanName? Is it possible to create public class MyNode: Mindscape.WpfPropertyGrid.Node or if its not that easy can you please add event to your Node public delegate string GetHumanNameHandler(Node node);
|
|
|
HumanName is taken from the display name of the property. You can customise this at compile time by applying DisplayNameAttribute to the property. If you need to create display names at runtime, you can implement ICustomTypeDescriptor and return custom PropertyDescriptors from GetProperties. Your custom PropertyDescriptor can then override the Name property. Alternatively, and more similar to your event suggestion, you can implement an IValueConverter that maps a Node to its display name, and use that value converter in your PropertyNameTemplate DataTemplate. Such a value converter would contain essentially the same code as your suggested OnGetHumanName handler or your HumanName override. Note that the DataTemplate receives a PropertyGridRow so you would want the binding to be {Binding Node} if you are to pass a Node rather than a PropertyGridRow to your value converter. The upside of the first approach is that it doesn't require a custom property name template. The downside is that, if you are generating the display names at runtime, it is quite a bit more complex. So if DisplayNameAttribute will do the job then I would use that; otherwise use custom template and value converter. It should be pretty easy to create a suitable template based on the sample I posted earlier; give me a shout if you run into any problems. |
|
|
Yes IValueConverter helps! But I need construct label name based on some values in parent node(s). For that purpose I implemented IMultiValueConverter to pass both Node and TreeViewItem <TextBlock Name="NameBlock" VerticalAlignment="Center" Converter just return HumanName at moment public sealed class NodeToTextConverter: IMultiValueConverter //I will add my logic later It works unitl i uncomment the second binding <Binding RelativeSource="{RelativeSource AncestorType={x:Type ms:TreeListViewItem}}"/> If I add it to Multi Binding all labels are empty !! |
|
|
What appears to be going on here is that using RelativeSource AncestorType is causing WPF to instantiate the ancestor controls (as I guess it must do to some extent in order to evaluate the binding). Because the binding is not yet complete, the property grid labels get instantiated with empty labels and therefore get automeasured to zero width. The binding then completes and returns, but it is too late for the label widths. Your labels are not empty: they are just squashed to zero width (in fact if you hover the mouse near the left of the grid you get a resize cursor and can bring them back). The workaround is to specify a MinWidth property for your TextBlock. This overrides the text-based automeasurement, ensuring that your labels get a reasonable width when WPF evaluates the RelativeSource. This will not affect the user experience: your users will still be able to resize the column to below the MinWidth, and the text block will still grow to fit the column width if the user expands it (this is why you should specify MinWidth rather than Width). Here is my test sample: <TextBlock Background="LightBlue" MinWidth="100"> |
|