How can I bind Wpf DataGridColumn to an object?

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2009-05-19T17:16:48Z Indexed on 2010/04/15 16:03 UTC
Read the original article Hit count: 267

Filed under:
|

I want to bind the columns of my WPF DataGrid to some objects in a Dictionary like this:

Binding Path=Objects[i]

where Objects is my Dictionary of objects, so that each cell will represent an Object element. How can I do that?

I suppose that I need to create a template for my cell, which I did, but how to get the result of column binding in my template? I know that by default the content of a DataGridCell is a TextBlock and it's Text property is set through column binding result, but if that result is an object I guess that I have to create a ContentTemplate. How do I do that, as the stuff I tried is not displaying anything.

Here it is what I tried:

<Style x:Key="CellStyle" TargetType="{x:Type dg:DataGridCell}">
    <Setter Property="Template"> ---it should realy be ContentTemplate?
      <Setter.Value>
        <ControlTemplate>
          <controls:DataGridCellControl CurrentObject="{Binding }"/> -- I would expect to get the object like this for this column path : Path=Objects[i] but is not working
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

So, to make myself completly clear, i want to get in CurrentObject property of my DataGridCellControl the current object that should result if I set the column binding in my data grid like this Path=Objects[i].

Thank you for any suggestion,

John.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about datagrid