Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
450
Display Initial Cell Value in a Tooltip
posted

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:

  • DataValueChangedNotificationsActive="True"
  • DataValueChangedHistoryLimit="2"
  • CellValuePresenterStyle="{StaticResource CellStyles}"

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!

Parents
No Data
Reply
  • 450
    posted

    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"

Children