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
490
Setting the xamDataGrid DataContext to an object
posted

Hello,

I want to set the DataContext of my grid to an object and use a collection of that objects as the grids data source.  It looks like I had no problem doing that but I have some questions about how the rows are generated for the grid.

I see that each public property of the object held in the collection is used as a column of the grid.  Does the column name have to be the same as the property name?  If not, how can  I change it?  Do I need to predefine the grids columns in xaml?  If I do that, how will the binding work?

If I want to set the column widths and am not defining them in xaml, which event should I be listening to so that I can set the column widths in code?

If there are any examples of binding to a collection of objects that would also be useful.

Thanks.

Parents
No Data
Reply
  • 2180
    Suggested Answer
    Offline posted

    Hello,

     

    You can change the columns settings by defining the FieldLayout and the Fields in xaml like this: 

     

    <igDP:XamDataGrid.FieldLayouts>       

    <igDP:FieldLayout >         

    <igDP:FieldLayout.Fields>           

    <igDP:Field Name="passingyards" Label="Total Passing Yards" Width="200" />            

    <igDP:Field Name="passingyardsperattempt" Label="Passing Yards/Attempt" />           

    <igDP:Field Name="passingyardspergame" Label="Passing Yards/Game" />

    </igDP:FieldLayout.Fields>      

    </igDP:FieldLayout>

    <igDP:XamDataGrid.FieldLayouts>        

     

    You can hook to XamDataGrid's Loaded event or FieldLayoutInitialized event using this code:

    xamDataGrid.FieldLayouts[0].Fields["passingyards"].Width = new FieldLength(200);

    Hope this helps.

     

    Thanks,

    Diyan Dimitrov

     

     

Children
No Data