Hey Guys,
I have a couple of editable cells in my XamDataGrid (Infragistics 14, .Net 4.0, Windows 7) and I'd like to display the initial values of these cells in tooltips - displayed when you hover over any of the editable cells. I tried doing this by adding a style like the following:
<Style x:Key="CellStyles" TargetType="{x:Type ig:CellValuePresenter}" BasedOn="{StaticResource {x:Type ig:CellValuePresenter}}" > <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEditingAllowed}" Value="True"> <Setter Property="ToolTip"> <Setter.Value> <Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ig:CellValuePresenter}, Path=ValueHistory.Count}" ContentStringFormat="Original Value: {0}"/></Setter.Value></Setter> </DataTrigger></Style.Triggers> </Style>
This was more of a test to see if I can show the ValueHistory.Count in the tooltip next to some text but it looks like my binding's messed up; I receive the following error:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Infragistics.Windows.DataPresenter.CellValuePresenter', AncestorLevel='1''. BindingExpression:Path=ValueHistory.Count; DataItem=null; target element is 'Label' (Name=''); target property is 'Content' (type 'Object')
Any suggestions on the above?
In regards to my actual usecase, I'm having trouble accessing the initial value from the ValueHistory. I set the three properties below as follows:
But I can't access the original value from the ValueHistory list in my xaml. Any ideas? Is there a better way to go about doing this? I considered binding a property to the tool tip value but I need the style to work for any editable cell on any grid that uses this style. Thanks in advance for your help!
Is there a better way to go around getting the initial value of a cell?
Hey Nikolov,
Thank you for your response. It seems your demo is very similar to my approach - I was able to resolve both my issues with the code I posted last night. I was wondering if there's a better way to go about getting the initial value of a cell?
Hello Javier,
Thank you for your post.
I have been looking into it. I am glad that you have managed to resolve your first issue. About your requirement for StringFormat, what I can suggest is to add the string that you want to display before cell`s value directly in your converter. I created a short sample application based on your scenario to show you how you can implement this. If you are not able to reproduce the issue with the attached sample application, would you please modify it with the functionality, that you are using, so it reproduces the issue. This way I would be able to further investigate this for you and provide you with more detailed information on this matter. Please let me know if I am missing something about your scenario.
Please let me know if you need any further assistance on the matter.
I got this to work using the following style:
<Setter Property="ToolTip"> <Setter.Value> <MultiBinding Converter="{StaticResource CellValueHistoryConverter}" StringFormat="Old Value: {0}"> <Binding RelativeSource="{RelativeSource Mode=Self}" Path="Field"/> <Binding RelativeSource="{RelativeSource Mode=Self}" Path="Record"/> </MultiBinding> </Setter.Value> </Setter>
And the following converter:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null || values.Length != 2) return null;
var field = values[0] as Field; var record = values[1] as DataRecord; if (record == null || field == null) return null; var dataHistory = record.GetDataValueHistory(field); var lastItem = (dataHistory == null) ? null : dataHistory.Last(); return lastItem == null ? null : lastItem.Value; }
Is this the suggested way to do this or do I have other options? By the way, my string format is still not showing up - I had to add it to my converter
I tried changing the setter to the following:
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ValueHistory[ValueHistory.Count-1].Value}"/>
I used "ValueHistory[ValueHistory.Count-1].Value" because I noticed while debugging that the edits are appended to the list. I get the following errorwith this approach:
System.Windows.Data Error: 40 : BindingExpression path error: '[]' property not found on 'object' ''DataValueInfoHistory' (HashCode=6762647)'. BindingExpression:Path=ValueHistory[ValueHistory.Count-1].Value; DataItem='CellValuePresenter' (Name=''); target element is 'CellValuePresenter' (Name=''); target property is 'ToolTip' (type 'Object')
If possible, I would also like the formatting that I described above for my tool tip - "Old Value: xyz"