3

Example:

<ListView Name="lvAnyList" ItemsSource="{Binding}">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="xx" DisplayMemberBinding="{Binding XX}" CellTemplate="{DynamicResource MyDataTemplate}"/>
      <GridViewColumn Header="yy">
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Text="{Binding YY}" />
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
    </GridView>
  </ListView.View>
</ListView> 

If I access the TextBlock inside DataTemplate I will have access to information about the bound path. But I don't know how to find (starting from the TextBlock) its containing GridViewColumn (which is in the GridViewRowPresenter columns list) and compare it to the grid's GridViewColumn (from GridViewHeaderRowPresenter column list) to get the header's name.

At the end I should have the pairs: xx->XX, yy->YY

I can find a list of all TextBlocks inside ListView by using this:

GridViewRowPresenter gvrp = ControlAux.GetVisualDescendants<GridViewRowPresenter>(element).FirstOrDefault();
IEnumerable<TextBlock> entb = GetVisualDescendants<TextBlock>(gvrp);

I can find a list of all GridViewColumnHeaders:

GridViewHeaderRowPresenter gvhrp = ControlAux.GetVisualDescendants<GridViewHeaderRowPresenter>(element).FirstOrDefault();

And I cannot find the connection between the TextBlocks and the GridViewColumns...

I hope this is understandable.

Stedy
  • 7,359
  • 14
  • 57
  • 77
ragi
  • 31
  • 3
  • Did you find any way for this?? i am having same kind of issue and I've not got any solution for this. – Jolly Apr 19 '19 at 11:27

1 Answers1

0

GridViewColumns are abstract objects they never appear anywhere in the UI, you can try to name the column and bind it to the Tag of a control where you need it using ElementName or if that fails a Source with x:Reference on the name.

H.B.
  • 166,899
  • 29
  • 327
  • 400