Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
290
Set field tooltip through code-behind
posted

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

Parents
  • 6365
    Offline posted

    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. 

    XamDataGrid_fieldTooltip.zip
Reply Children