Using Multiple SfDataGrid in One Window that Binds to Different View Models

Hi,

I would like to use two different sfDataGrids in one XAML page. I have created two View Models in two different classes (ViewModel1 & ViewModel2). How do I bind the sfDataGrids to their respective View Models in XAML? In XAML, I can only define one data context using the code below. I cannot define another "<local:ViewModel2/>".

    <Page.DataContext>
        <local:ViewModel1/>
    </Page.DataContext>

Thanks,

1 Reply 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team May 12, 2021 08:24 AM UTC

Hi Sam Shen, 

Thanks for contacting Syncfusion products. 

You can achieve this requirement be setting DataContext separately for the SDataGrids as shown in the following code example.  

Code example :  

<syncfusion:SfDataGrid.DataContext> 
    <local:ViewModel1/> 
</syncfusion:SfDataGrid.DataContext> 

Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Marked as answer
Loader.
Up arrow icon