1
votes

I am trying to create a style for my XamDataGrid so that I can determine what values to show in a tooltip based on the current cell that is being hovered over.

I am trying the below:

<Style x:Key="MyCVPStyle" TargetType="{x:Type igDP:CellValuePresenter}">
        <Setter Property="ToolTip">
            <Setter.Value>
                <StackPanel>
                    <ListView ItemsSource="{Binding RelativeSource={...}, Path=Field, Converter={StaticResource MyFieldConverter}}">
...

The DataContext of the style is set to the DataRecord. The problem I am having is that I do not know how to access the actual field of the cell value presenter.

I tried setting the source to:

{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Path=Field

but that fails with a binding error:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Infragistics.Windows.DataPresenter.CellValuePresenter', AncestorLevel='1''. BindingExpression:Path=Field; DataItem=null; target element is 'ListView' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')

How can I access/bind to the CellValuePresenter.Field so I can pass that value to my converter?

As a reference, I have other CellValuePresenter styles that work without issue where I access the Field. For example, here the second binding param is the Field, accessed by referencing Self:

<Setter Property="BorderThickness">
  <Setter.Value>
    <MultiBinding Converter="{StaticResource BorderThicknessConverter}">
      <MultiBinding.Bindings>
        <Binding Path="DataItem" />
        <Binding RelativeSource="{RelativeSource Self}" Path="Field" />
      </MultiBinding.Bindings>
    </MultiBinding>
  </Setter.Value>
</Setter>
3

3 Answers

4
votes

You could use the PlacementTarget property of ToolTip, which will be the CellValuePresenter, and set it as the DataContext that the ListView is binding to:

<Setter Property="ToolTip">
    <Setter.Value>
        <ToolTip DataContext="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget}">
            <StackPanel>
                <ListView ItemsSource="{Binding Path=Field, Converter={StaticResource MyFieldConverter}}"></ListView>
            </StackPanel>
        </ToolTip>
    </Setter.Value>
</Setter>
1
votes

I found an alternate solution that I feel is more straight forward.

Create the following style (I believe the property you are trying to bind ItemsSource to is named Field)

<Style x:Key="MyCVPStyle" TargetType="{x:Type igDP:CellValuePresenter}">
    <Setter Property="ToolTip">
        <Setter.Value>
            <StackPanel>
                <ListView ItemsSource="{Binding Path=Cells[Field].Value}" />
            </StackPanel>
        </Setter.Value>
    </Setter>
</Style>

But this does require that you have the field you're binding your ItemsSource to defined in FieldLayout.Fields. You may want to set the Visibility of that field to collapsed. I've also included the field that has the tooltip style applied to it.

<igDP:Field Label="Value" Name="Value" >
    <igDP:Field.Settings>
        <igDP:FieldSettings CellValuePresenterStyle="{StaticResource ResourceKey=MyCVPStyle}" />
    </igDP:Field.Settings>
</igDP:Field>
<igDP:Field Label="Field" Name="Field" Visibility="Collapsed" />
0
votes

You could use a different style for the different fields within the XamDataGrid so that each style would already be set up for the specific field.

The reason why the binding is failing is because the tooltip is shown in a pop up so it is another window and not in the same visual tree as the CellValuePresenter.