Hello,
Is there a way to set the tooltip of a XamDataGrid Field to it's own value? Something like,
Me.Grid.FieldLayouts(0).Fields("Description").Tooltip = Me.Grid.FieldLayouts(0).Fields("Description").Value
I want to do this in a function where I am passing Field as a parameter.
Thanks,
Mansi
Hello Mansi,
I have been looking into your issue and you should be able to achieve this by setting the Tooltip property of the LabelPresenter for every Field.
First Approach:
If you would like to set the Tooltip to the Name (or Label) of the Field, the fastest way of achieving this would be handling the Loaded event of the LabelPresenter and implementing the logic directly:
XAML: <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:LabelPresenter}"> <EventSetter Event="Loaded" Handler="LabelPresenter_Loaded"/> </Style> </igDP:XamDataGrid.Resources>
Code-Behind: private void LabelPresenter_Loaded(object sender, RoutedEventArgs e) { var lb = (sender as LabelPresenter); lb.ToolTip = lb.Field.Name; } Second Approach:
If you would like to this by using a method on runtime, you will have to get all the LabelPresenters first. This can be achieved by defining a new field collection of LabelPresenters in your MainWindow class and populate it with the LabelPresenters as soon as they have loaded, which means we can use the Loaded event of the LabelPresenter in this case as well. Afterwards all we have to do is invoke the same logic (in this case method) as in the first approach for every single field of the initial FieldLayout.
I have prepared a sample application where this approach has been implemented.Would you please take a look at the snippet and the sample and if you need any further assistance on this matter, please let me know.
Hi Tacho, I ran the application, but I don't see tooltips on the cells. That's where I want the tooltips to show the contents of the cell. So if a cell content is too big for the cell width, the user can see it in the tooltip.
Will the label presenter second approach work in this case?
Right now I am doing this in the XAML (see below), but I need this done from the code behind (if there are many columns / many forms, I don't want to write the following for all of them). Then I will remove the following code from my XAML:
<igDP:Field Name="{x:Static myObject:_DESCRIPTION}"
Label="{x:Static myObject.MSG_DESCRIPTION}" Width="400"> <igDP:Field.Settings> <igDP:FieldSettings> <!-- ToolTip --> <igDP:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Static vCommon:clsWinGlobals.KEY_CELL_VALUE_PRESENTER_STYLE}}"> <Setter Property="ToolTip" Value="{Binding RelativeSource = {RelativeSource Mode=Self}, Path=Value }"/> </Style> </igDP:FieldSettings.CellValuePresenterStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
If you would like to keep the style functionality for all controls using the CellValuePresenter in the current application, you should be able to achieve this by placing the Style inside the resources of the application (Inside App.xaml).
Would you please take a look at this approach and if it does not fit your behavior, please let me know.
Looking forward to hearing from you.
Hello Mansi,Both approaches are setting Tooltips for the LabelPresenters only. The LabelPresenters are the visual elements responsible for the visualization of the Label for every Field (In our case Name, Id, Weight). If you would like to set the Tooltip for every CellValuePresenter to its respective Value, you should be able to achieve this by simply binding the Tooltip property of the CellValuePresenter for the Value property of the CellValuePresenter by using the following Style:
<Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="ToolTip" Value="{Binding RelativeSource = {RelativeSource Mode=Self}, Path=Value }"/></Style>
If you require any further assistance on this matter, please do not hesitate to ask.