Friday, August 3, 2018

XamDataGrid Tooltips do not work

Even though the XamDataGrid's TextField column supports a Tooltip and TooltipService property they appear to be ignored. This is consistent with Infragistic's philosophy of taking things that are easy and making them difficult.

Don't just take my word for it. Let's create a project that demonstrates how tool tips don't work, then look at the "solution"
.
Create a new WPF Application project and call it XamDataGridTooltip.


Don't forget to add the references to Infragistics to your project.



The XAML looks like this. Notice I'm not even trying to bind the tool tip. I'll take anything at this point!

<Window x:Class="XamDataGridTooltip.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:XamDataGridTooltip"
        xmlns:igDP="http://infragistics.com/DataPresenter"
        mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"
        DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <igDP:XamDataGrid Theme="LunaSilver" DataSource="{Binding SomeText}" GroupByAreaLocation="None" VerticalAlignment="Stretch">
        <igDP:XamDataGrid.FieldLayoutSettings>
            <igDP:FieldLayoutSettings SelectionTypeRecord="Single" AutoGenerateFields="False"/>
        </igDP:XamDataGrid.FieldLayoutSettings>
        <igDP:XamDataGrid.FieldSettings>
            <igDP:FieldSettings AllowSummaries="False" SummaryUIType="SingleSelect" LabelTextAlignment="Center" AllowEdit="false" />
        </igDP:XamDataGrid.FieldSettings>
        <igDP:XamDataGrid.FieldLayouts>
            <igDP:FieldLayout Description="SomeText" Key="SomeText">
                <igDP:FieldLayout.Fields>
                    <igDP:TextField Label="SomeText" Name="Text" ToolTip="Some Text" ToolTipService.ShowOnDisabled="True">
                </igDP:FieldLayout.Fields>
            </igDP:FieldLayout>
        </igDP:XamDataGrid.FieldLayouts>
    </igDP:XamDataGrid>
</Window>


The code behind looks like this. I didn't implement INotifyPropertyChanged because I want to focus on the tooltip.


using System;
using System.Collections.Generic;
using System.Windows;

namespace XamDataGridTooltip
{
    public partial class MainWindow : Window
    {
        public class cText
        {
            public cText(String Text)
            {
                this.Text = Text;
            }

            private String _Text;
            public String Text
            {
                get { return _Text; }
                set { _Text = value; }
            }
        }

        public List<cText> SomeText
        {
            get { return new List<cText> { new cText("Some text"), new cText("Some more text") }; }
        }
       
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

If you run the project, you will see there are no tool tips.

No tool tip :-(
Now replace the TextField with this XAML. It assigns a tool tip to the cell value presenter via a style. Note the use of DataItem which removes the need to use a ProxyElement. Thank goodness I only have to do this on one column!


                    <igDP:TextField Label="SomeText" Name="Text">
                        <igDP:TextField.Settings>
                            <igDP:FieldSettings>
                                <igDP:FieldSettings.CellValuePresenterStyle>
                                    <Style TargetType="igDP:CellValuePresenter">
                                        <Setter Property="ToolTip" Value="{Binding DataItem.Text}"/>
                                    </Style>
                                </igDP:FieldSettings.CellValuePresenterStyle>
                            </igDP:FieldSettings>
                        </igDP:TextField.Settings>
                    </igDP:TextField>

Tool tip :-)



No comments:

Post a Comment