wpftoolkit icon indicating copy to clipboard operation
wpftoolkit copied to clipboard

PropertyGrid - Is it possible that each PropertyDefinition has a ToolTip?

Open kabircosta opened this issue 3 years ago • 4 comments

Is it possible that each PropertyDefinition has a specific tooltip?

For example:

<xctk:PropertyDefinition TargetProperties="MyProperty" ToolTip="My tooltip"/>

or

                <xctk:PropertyDefinition TargetProperties="MyProperty">
                    <xctk:PropertyDefinition.ToolTip>
                        <StackPanel>
                            <TextBlock Text="MyToolTip"/>
                        </StackPanel>
                    </xctk:PropertyDefinition.ToolTip>
                </xctk:PropertyDefinition>
            </xctk:PropertyGrid.PropertyDefinitions>

or doing the same thing in another way?

kabircosta avatar Apr 19 '21 12:04 kabircosta

Hi, The idea is to use the Description attribute : something like: [Description("My Description Data")] public string MyProperty { get; set; }

From there, clicking on a PropertyItem will display the description at the bottom of the PropertyGrid. If you want to display this Description as a tooltip, you can set the PropertyGrid.ShowDescriptionByTooltip to true. Doing a mouse over of a PropertyItem will now display a tooltip.

XceedBoucherS avatar Apr 19 '21 18:04 XceedBoucherS

XceedBoucherS, first of all, thank you so much for your answer. The idea is to place a complex structure inside my tooltip, with Images, StackPanels, TextBox with specific styles and other constrols (as instructions).

kabircosta avatar Apr 22 '21 07:04 kabircosta

Ok, I see. This is not currently supported. We will have a look into this. Thank you for the idea.

XceedBoucherS avatar Apr 22 '21 13:04 XceedBoucherS

In the upcoming release (v4.4), you will be able to provide complex tooltips for the PropertyItems through style and use a Converter to display the control you want in the Tooltip :

<xctk:PropertyGrid.Resources>                      
                <Style TargetType="xctk:PropertyItem">
                  <Setter Property="ToolTip">
                        <Setter.Value>
                          <StackPanel Orientation="Horizontal">
                            <Image Source="{Binding ., Converter={StaticResource myConverter}}"
                                    Height="36"
                                    Width="36" />
                            <Label HorizontalAlignment="Center"
                                    Content="My Text" />
                          </StackPanel>
                        </Setter.Value>
                      </Setter>
                </Style>
            </xctk:PropertyGrid.Resources>
public class Converter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
          var propertyItem = value as PropertyItem;
          if( propertyItem != null )
          {
            BitmapImage img = null;
            if( propertyItem.DisplayName == "Command" )
            {
              img = new BitmapImage( new Uri( "/Xceed.Wpf.Toolkit.LiveExplorer;component/Samples/PropertyGrid/OpenSourceImages/Localization.png", UriKind.Relative ) );
            }
            else
            {
              img = new BitmapImage( new Uri( "/Xceed.Wpf.Toolkit.LiveExplorer;component/Samples/PropertyGrid/Resources/woman.png", UriKind.Relative ) );
            }

            return img;
          }

          return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
}

evancekafando avatar Dec 29 '21 15:12 evancekafando