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
30
XamDataGrid in a user control
posted

Hi,

I want to show different grids based on business criteria with different columns.

The idea is to have a separate UserControl with a grid and in parent page change it(by hiding/showing ). 

I tried embedding the grid in user control with no data context, so it inherit parent's, but nothing shows up when doing a normal binding in user control - this works fine if I have it in parent page :

<XamDataGrid Name="test" ActiveDataItem="{Binding SelectedItem}">

<Field x:Name="txt_ID" Name="Id" Label="ID">
<Field.Settings>
<FieldSettings AllowEdit="False" >
</FieldSettings>
</Field.Settings>
</Field>

</XamDataGrid>

  • 28945
    Verified Answer
    Offline posted

    Hello and thank you for contacting Infragistics. As long as the DataContext of the Window that has the usercontrol is set you can bind to the grid. Also the datasource property of the XamDataGrid needs to be set. I attached a sample binding a grid placed in a user control where the DataSource is a view model with a list not created directly in the usercontrol's code behind but the main window's code behind. Let me know if you have any questions.

     WpfApp6.zip