Josh,
There is another way to approach this, don't use any styles and just do it in the code-behind directly.
Bolow is the sample code:
private void OnMouseMove(object sender, System.Windows.Input.MouseEventArgs e) // this is a mouse over event handler for XamDataGrid { DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource, typeof(DataRecordPresenter), true) as DataRecordPresenter;
if (drp == null) { return; }
// //TODO: show your tool tip, you can use reflection to get your current underlying data record, for example: // StringBuilder toolTip = new StringBuilder(); string label = string.Empty; // // Especially if you are using Linq as your underling data source, then reflection is // the unique way to get the values of kinds of fields. Type type = drp.DataRecord.DataItem.GetType(); System.Reflection.PropertyInfo[ pInfos = type.GetProperties();
foreach (System.Reflection.PropertyInfo pi in pInfos) { label = xamDataGrid.FieldLayouts[0].Fields[pi.Name].Label.ToString(); // xamDataGrid is your XamDataGrid control name. toolTip.Append(label); toolTip.Append(": "); toolTip.Append(pi.GetValue(drp.DataRecord.DataItem, null)); toolTip.Append(Environment.NewLine); } drp.ToolTip = toolTip.Length > 0 ? toolTip.ToString() : null; }
Hope this helps.
Corin
I found this approach to be the easiest by far Say I had a xamDatagrid bound like this, using the following test class
public class TestClass { public Int32 Id { get; set; } public String Name { get; set; } public String Department { get; set; } public override string ToString() { return string.Format("{0} {1} {2}", Id, Name, Department); } }
And the grid datasource was like this
List<TestClass> classes = new List<TestClass> { new TestClass { Id = 1, Department ="xyz1", Name = "Grrr1"}, new TestClass { Id = 2, Department ="xyz2", Name = "Grrr2"}, new TestClass { Id = 3, Department ="xyz3", Name = "Grrr3"} }; dgSearchResults.DataSource = classes;
And then I set some styles like this.
<igDP:XamDataGrid x:Name="dgSearchResults" Margin="0" Theme="RoyaleStrong" Visibility="Visible" Background="{DynamicResource mainControlAreaBackGround}"> <igDP:XamDataGrid.Resources> <ControlTemplate x:Key="RoundToolTip" TargetType="{x:Type ToolTip}"> <Grid > <Grid.RowDefinitions> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Rectangle RadiusX="5" RadiusY="5" Fill="Black" Stroke="Black" StrokeThickness="1" /> <Grid > <Grid.RowDefinitions> <RowDefinition Height="3" /> <RowDefinition Height="*" /> <RowDefinition Height="3" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="3"/> <ColumnDefinition Width="*" /> <ColumnDefinition Width="3"/> </Grid.ColumnDefinitions> <Border Grid.Column="1" Grid.Row="1"> <StackPanel> <ContentControl Content="{TemplateBinding Content}" /> </StackPanel> </Border> </Grid> </Grid> </ControlTemplate> <Style TargetType="{x:Type ToolTip}"> <Setter Property="Template" Value="{StaticResource RoundToolTip}" /> </Style> <ContentControl x:Key="ToolTipContent" Background="Transparent"> <Border HorizontalAlignment="Stretch" BorderBrush="Black" Background="White" Margin="0" Grid.Row="0" Grid.Column="2" VerticalAlignment="Stretch" Height="260" Opacity="0.95" BorderThickness="5" CornerRadius="3" > <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <StackPanel Background="Black" Orientation="Horizontal" HorizontalAlignment="Stretch"> <Label VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black" FontSize="18" Foreground="White" Grid.ColumnSpan="2">Payment</Label> <Label VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black" FontSize="18" Foreground="White" Grid.ColumnSpan="2" Content="{Binding Path=Cells[Id].Value}"></Label> <Label VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black" FontSize="18" Foreground="White" Grid.ColumnSpan="2">history:</Label> </StackPanel> <StackPanel Grid.Row="1"> <StackPanel Orientation="Horizontal"> <Label Content="Full content"/> <Label Content="{Binding}"/> </StackPanel> </StackPanel> </Grid> </Border> </ContentControl> <Style TargetType="{x:Type igDP:DataRecordPresenter}"> <Setter Property="ToolTip" Value="{DynamicResource ToolTipContent}" /> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="True" /> </igDP:XamDataGrid.FieldLayoutSettings> </igDP:XamDataGrid>
Now considering how useful a tooltip is why the heck does it have to be this hard, it just shouldn't be that hard.
Sachab,
I was looking at your example and was wondering if you could send me the source code of you example.
Thanks,
Bryan