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
|
Any chance you would consider supporting System.ComponentModel.CategoryAttribute or does that relate to the discussion here: http://www.mindscape.co.nz/forums/Thread.aspx?PostID=1927 ?? Also wondering what the easiest means is for declaring a tooltip for a property? Any support for that?
|
|
|
We do support CategoryAttribute, just not in the way that you would expect *grin*. To group using CategoryAttribute, you need to go to grid.BindingView, get the default collection view, and add a new PropertyGroupDescription using the NodeToCategoryConverter to the GroupDescriptions collection. There's an example at http://www.mindscape.co.nz/blog/index.php/2008/01/27/sorting-and-grouping-in-the-wpf-property-grid/. If you have a recent nightly, there is now a handy shortcut that you can use in XAML: <ms:PropertyGrid Grouping='{x:Static ms:PropertyGrouping.ByCategory}' /> See How Do I > Group Properties by Category in the updated help file. We don't have any built-in support for tooltips, but again if you are using a recent nightly you can create your own template for where it displays the property name by setting the PropertyGrid.PropertyNameTemplate property. So you could create a template that includes a tooltip. Note that if you do this you are responsible for providing the ENTIRE left hand side of the grid, including the expand/collapse UI if required. I'm afraid we don't have a sample for this feature yet but we would be happy to advise and assist. |
|
|
I am also interested in having tooltips for the property names. Did the subject evolve in the passed year? Any sample available? Thanks. |
|
|
I agree tooltips would be nice outside of the description property.
|
|
|
Righty ho, we have now added tooltip support and this will be included in nightly builds dated 22 July 2009 and above, available from about 1430 GMT. You will need to do two things: 1. Set ToolTipService.IsEnabled on the grid. 2. Set the new PropertyNameToolTipTemplate to a DataTemplate for the desired content. This DataTemplate receives a PropertyGridRow so you will typically be using the Node, probably with a suitable converter. Important: there is no default template, so if you turn tooltips on but do not specify a template then you will get very unfriendly tooltips! Quick example: <ms:PropertyGrid ToolTipService.IsEnabled="True"> In this example, the tooltip just duplicates the contents of the property name cell, which is not very useful unless you have lots of long names, but you can obviously bind to the Node and use an IValueConverter to extract the description or whatever. Please let us know if you run into any problems. |
|
|
I implemented it as follows, just to check the look and feel: <ms:PropertyGrid x:Name="propertyGrid" AllowModifyCollections="False" Style="{StaticResource {x:Static ms:Alloy.StyleKey}}" xcdg:RowSelector.Visible="False" ToolTipService.IsEnabled="True"> <ms:PropertyGrid.PropertyNameToolTipTemplate> <DataTemplate> <TextBlock Text="{Binding Node.HumanName}" /> </DataTemplate> </ms:PropertyGrid.PropertyNameToolTipTemplate> </ms:PropertyGrid>
Nothing happened. Please help. |
|
|
Ah, sorry, hadn't realised you were using one of the visual styles. I have now added tooltip support to all the visual styles and this will be included in the 29 July nightly build, available from about 1430 GMT. If you are using a customised version of a style then you will need to update the property cell template to display tooltips -- let me know if this is the case and I will post sample code. |
|
|
To add tooltip support to a custom style: 1. Find the cell template for the left hand column. In the Mindscape styles, this is called FancyNodeTemplate, and in the current build of Alloy.xaml begins on line 321. 2. Locate the element on which you want the tooltip to appear. This will typically be a TextBlock: in the original Alloy.xaml it is the TextBlock which appears inside the second border (line 339 in the current build of Alloy.xaml). 3. Add the following attributes to this TextBlock: ToolTipService.IsEnabled="{Binding Path=(ToolTipService.IsEnabled), RelativeSource={RelativeSource AncestorType={x:Type local:PropertyGrid}}}" Tag="{Binding PropertyNameToolTipTemplate, RelativeSource={RelativeSource AncestorType={x:Type local:PropertyGrid}}}" 4. Add the following property element to this TextBlock (you will probably need to split out the end tag first): <ToolTipService.ToolTip> You should end up with something that looks like this: <TextBlock Text="{Binding Node.HumanName}" Let us know if you still see problems. |
|
|
I will need to put the equivalent of : Could you pls post the correct code? I just can't figure out the source of the binding (It shouldn't be the Property Grid object since Node is not one of its properties). |
|
|
The source of the binding will be a PropertyGridRow. Therefore your PropertyNameToolTipTemplate code is correct: here is the code from our test app which you will see is identical: <ms:PropertyGrid ToolTipService.IsEnabled="True" Style="{StaticResource {x:Static ms:Alloy.StyleKey}}"><ms:PropertyGrid.PropertyNameToolTipTemplate> <DataTemplate> <TextBlock Text="{Binding Node.HumanName}" /> </DataTemplate> </ms:PropertyGrid.PropertyNameToolTipTemplate> </ms:PropertyGrid> Don't forget you need to update your custom style as shown in the previous message. |
|
|
I did as you suggested and tooltip is working. Nonetheless, the code would be much simpler if I could perform the TextBlock binding in the code behind. The issue I have is that I don't know how to specify a PropertyGridRow as the binding source object (no PropertyGridRow object is available for binding). Can you help with a code snippet? |
|
|
You don't need to explicitly specify a PropertyGridRow as the binding source object: this is supplied automatically to the DataTemplate by the ToolTip control that you provided in your custom style. So when you write this in your custom style: <ToolTipService.ToolTip> that's what brings in the PropertyGridRow and feeds it to the DataTemplate. So when you do the TextBlock Text="{Binding Node.HumanName}", that's already being fed with the PropertyGridRow because the ContentTemplate of the ToolTip (the PropertyNameToolTipTemplate) is being applied to the Content (the PGR). WPF does not provide a natural way to perform this binding in code-behind. Instead you would typically use something like an IValueConverter. If you want to construct the binding dynamically then you could probably do it by using a FrameworkElementFactory to construct the DataTemplate on the fly. I'm not really able to provide a code snippet because I'm not sure what you want to achieve by performing the TextBlock binding in the code-behind rather than in the DataTemplate XAML. If you could say a bit more about why you want to use code rather than XAML or what effect you are trying to achieve that is inconvenient to do in XAML then I'd be glad to help out though! |
|
|
I am providing data to the property grid through the ItemsSource property, and the property names, values and tooltips come from a xml file. To associate the tooltips with Node, I am using a class (with property value and tooltip as members) instead of a value in the dictionary. But this forces me to have a custom editor to all the properties. Perhaps creating a dependency property for the Node would be better (my company bought the source code). Or modifying the binding ... |
|
|
Have you considered using "smart dictionary keys"? That is, instead of rolling the tooltip into the dictionary value, roll it into the dictionary key? That way, the values remain normal values, so the default editors will just work. E.g. create a TooltippedName class: public class TooltippedName { And make your ItemsSource a Dictionary<TooltippedName, object> instead of Dictionary<string, YourWrapperClass>. Now, from your TextBlock binding, you can get at the tool tip text as: {Binding Node.IndexedPropertyArguments[0].ToolTip} Smart dictionary keys are a really handy way of handling things like categories, tooltips, sort order etc. in an ItemsSource scenario; we'd strongly recommend them over wrapping the value. |
|
|
Nice. Thanks a lot. |
|
|
When feeding data to the grid through SelectedObject, what is the recommended way of passing the tooltips to the converter?
|
|
|
It depends *grin*. For example, you could put the tooltip text in an attribute: [Tooltip("Favourite colour")] The template/converter can get at the custom attributes collection via the Node.Property. On the other hand, perhaps you want to be able to localise the tooltips, so you want to put them in a resource file. In this case the converter might instead perform a resource lookup, e.g. on the Node.Name (or type and name). In any case, the broad approach is usually to create a converter which receives a Node. Then in your tool tip template, you set up a binding with a Path of Node and an instance of this converter. The converter can, however, use whatever strategy is appropriate to your application to convert the Node to a tooltip, e.g. property metadata (via the .Property property), property name, etc. Hope this answers your question -- if not then let me know! |
|
|
Hi,
I am working in the code published by Adolfo.Aguiar from the previous post, we work in the same company. We have the tooltip working fine, but there are some fields where we do not want to show the tooltip. if I have a PropertyNameToolTipTemplate set to a TextBlock, I cannot remove the empty toolTip of the screen, even if I set the TextBlock.Text to string.Empy or null, or if I set the TextBlock Visibility to Collapsed Could you please help me to remove this tooltip from some properties ? In the same property grid editor, I would like to set the tooltip only for some of the properties. Plase find my code below : // XAML <ms:PropertyGrid.PropertyNameToolTipTemplate> // C# converter class : public class PropertyNameToDescriptionConverter : IValueConverter public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
|
|
The problem is that if the tooltip is enabled then WPF will display it even if there is no content. The solution is to override this default visibility. I believe you are using a custom build of the Alloy style, is that right? If so, you can handle this by customising the binding for the ToolTip.Visibility property in the FancyNodeTemplate: <ToolTip Visibility="{Binding Converter={StaticResource TooltipVisibility}}" /> where TooltipVisibility is an IValueConverter that determines whether there is a tooltip or not and returns Visible if there is and Collapsed if there isn't. For example suppose you were getting the tooltip from a DescriptionAttribute on the property: public class VisibleIfHasDescription : IValueConverter |
|