I'm trying to set a tooltip for a row in a XamDataGrid. Can be done?I want it when the mouse moves over the record tooltips becomes visible. Can somebody help me? Thanks
Hello,
If you want to see tooltips for each particular cell, you can do this via styles.
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},Path=Value}"></Setter>
Basically, all that I did was create a style that targets the CellValuePresenter (The presenter that displays the cell data) and set the tooltip property. I used a binding to the Value property off of the CellValuePresenter which is the value of the cell itself.
Also, I noticed that you mentioned record and not cell. If you want this tooltip to appear for the whole record, you will have to do something very similar and target the DataRecordCellArea instead.
<Style TargetType="{x:Type igDP:DataRecordCellArea}">
Then, you can initialize the setter and give it any value that you want.
if you really want to get fancy, you can create your own ToolTip object and bind that to all three values of the record. In the snippet below, I assigned the ToolTip of the DataRecordCellArea to the ToolTip object right below it. In there, I used the PlacementTarget property to set the DataContext of the Tooltip and then used simple binding to get the values from the record(PlacementTarget) to place in the TextBlocks.
<Setter Property="ToolTip" Value="{StaticResource SpecialToolTip}">
</Setter>
<ToolTip x:Key="SpecialToolTip" DataContext="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Path=Record.Cells[0].Value}"></TextBlock>
<TextBlock Text="{Binding Path=Record.Cells[1].Value}"></TextBlock>
<TextBlock Text="{Binding Path=Record.Cells[2].Value}"></TextBlock>
</StackPanel>
</ToolTip>
Hope this helps.
Hy Steve.
Do you know is it possible to have the tooltip for the header of a column for the grid?
I tryed to use ToolTipService but it's not working.
<my:Field Name="Title" ToolTipService.ToolTip="help" Label="{Binding Path=headerTitle, Source={StaticResource resStaticData}, Mode=OneWay}">
Thanks very much.
Nico
I do not think this will be possible with an unbound field or a bound field. There is no way to get back to the DataItem or even the Record for that matter when in the Label Presenter.
Sorry for any inconvenience that this may cause.
This is soclose to what I'm looking for. The one thing that it's missing is that I'm using an UnboundField that has BindingPath="Name". But in the tooltip, I want to bind to a property named "Age", rather than the value of Name or a hardcoded value (such as "The person's age"). I have not been able to figure out a way to access the Record.DataItem from within the UnboundField itself. I can't get the DataContext or pretty much any value other than the one that the BindingPath is set to.
I can do it if I apply a template to each field but I'd prefer to not HAVE to do it that way. Any ideas?
Fred
Hello Vinod,
If you want to set the tooltip from code, you can do the following.
Style s = new Style(typeof(LabelPresenter));s.Setters.Add(new Setter(ToolTipProperty,"MyToolTip"));this.XamDataGrid1.FieldLayouts[0].Fields[0].Settings.LabelPresenterStyle = s;
Of course, if you want to have the value be bound to the ToolTipService.ToolTip you will have to something similar to this.
Binding b = new Binding();b.Source = this.XamDataGrid1.FieldLayouts[0].Fields[0];b.Path = new PropertyPath(ToolTipService.ToolTipProperty);//b.RelativeSource = new RelativeSource(RelativeSourceMode.Self);//b.Path = new PropertyPath("Field.(ToolTipService.ToolTip)"); Style s = new Style(typeof(LabelPresenter));s.Setters.Add(new Setter(ToolTipProperty, b));this.XamDataGrid1.FieldLayouts[0].Fields[0].Settings.LabelPresenterStyle = s;
The binding can't be done exactly like it is done in xaml though. There seems to be a difference in how the xaml parser interprets Attached Properties as compared to the C# code. So you cant set the relativeSource to Self and the Path to Field.(ToolTipService.ToolTip) which I have commented out for you. You must set the source to the actual field and then the path to the ToolTipServices.ToolTipProperty. This should work.
Good Luck,
How to set the tooltip from Code. I am facing problem in setting tooltip from code. last style is getting appl;ied to the column header.
Thanks,
Vinod
Hy Josh.
This work's perfect. Thanks so very much.