Hi, I'm implementing WPF XamDataGrid over MVVM architecture. Wondering how can we set the tooltip text of the cells by binding to properties in the View Model file?Any suggestions will be welcome!Anshuman
Hello Anshuman,
Thank you for your reply. I am very glad that the approach I have suggested was helpful for you. If you wish to apply the tooltip to a particular field you can use the code that you have provided and it should work as expected.
If you need any further assistance please do not hesitate to ask.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Hi Krasimir,
This works like a charm! Thanks a lot.
I did make a little change as I needed the tooltip on a perticular field/cell rather than the whole record. Pasting the modified xaml code below. It works fine. Let me know if it is ok to do it this way.
Thanks a lot again!!!
Cheers!!!
<Window x:Class="CVP_ToolTip_MVVM.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:igDP="http://infragistics.com/DataPresenter"xmlns:local="clr-namespace:CVP_ToolTip_MVVM"Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.DataContext>
<local:DataGridViewModel/>
</Grid.DataContext>
<igDP:XamDataGrid DataSource="{Binding Data}">
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings
HighlightAlternateRecords="True"
AllowAddNew="True"
AddNewRecordLocation="OnBottom"
SelectionTypeCell="None"
SelectionTypeField="None"
SelectionTypeRecord="Single"
SupportDataErrorInfo="RecordsAndCells"
AutoGenerateFields="False"
/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.Resources />
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout IsDefault="False">
<igDP:FieldLayout.Fields>
<igDP:Field Name="ID" Label="ID" >
<igDP:Field.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="ToolTip">
<Setter.Value>
<StackPanel>
<TextBlock Text="{Binding DataItem.ID}"/>
<TextBlock Text="{Binding DataItem.Name}"/>
<TextBlock Text="{Binding DataItem.Age}"/>
</StackPanel>
</Setter.Value>
</Setter>
</Style>
</igDP:FieldSettings.CellValuePresenterStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>
<igDP:Field Name="Name" Label="Name" />
<igDP:Field Name="Age" Label="Age" />
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</Grid>
</Window>
Thank you for your post. I have created a sample application for you that demonstrates how you can add a ToolTip for the cells in the XamDataGrid. To do that I have created a style for the CellValuePresenter and add a setter for its ToopTip property. The data context of the CellValuePresenter is the DataRecord and you can use it to get the data item that corresponds to the record. Using the DataItem property of the DataRecord you can bind the tool tip to the properties of your view model.