We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Limited capability in binding ObservableCollection to WPF SfDataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

124368 Jun 5,2016 01:26 AM Jun 10,2016 01:57 PM WPF 3
loading
Tags: SfDataGrid
john mullally
Asked On June 5, 2016 01:26 AM

I have not been able to define the SfDataGrid ItemSource in XAML because the ObservableCollection is not populated in the ViewModel before the Views XAML runs.  Use of XAML DynamicResource does not help.  I can work around this problem by defining the ItemSource in code because this allows for making this definition after the ObservableCollection is populated.  This issue points to another issue that I cannot work around.  That other issue is that I cannot see the content of the SfDataGrid change when I add or delete records in the ObservableCollection.  I am using the latest Syncfusion WPF (May 3, 2016) on VS 2015. 

I have none of these problems using the WPF DataGrid that comes standard.  With that I can add or delete row programmatically and view the changes in the View and it works even with XAML StaticResource.

I have attached a simple version of the code to demonstrate these points.  It show two data grids (SfDataGrid & standard DataGrid) and it has an "Add New" button that adds a record to the ObservableCollection.  The "Add New" button was put there to demonstrate how the view changes a record is added to ObservableCollection. 

Thank You,for your help,
John

Attachment: SimpleGrid_baa17022.zip

Srinivasan Vasu [Syncfusion]
Replied On June 6, 2016 11:51 PM

Hi John, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your query and we are unable to run your sample which throws the “FodyWeaver task failed” error. We have prepared a sample as per your sample and checked the reported “ItemsSource not binding properly in SfDataGrid” issue in our sample. The SfDataGrid has been updated property while adding or deleting records programmatically.  
 
For your reference we have attached the tested sample. Please revert by modifying the attached sample based on your application along with the replication procedure. It will be helpful for us analyze further.  
 
 
Regards, 
Srinivasan 
 


john mullally
Replied On June 9, 2016 01:25 AM

Hi Srinivasan,

This example gets rid of the “FodyWeaver task failed” error.  It demonstrates the points I made in the opening post and it has no dependencies outside of VS 2015 & Syncfusion.


Thank you for the help,
John

Attachment: BindingExample_e4ab7c21.zip

Srinivasan Vasu [Syncfusion]
Replied On June 10, 2016 01:57 PM

Hi John, 
We have checked your query and While using SfDataGrid, you have bind the datasource to SfDataGrid.ItemsSource properly.  
 
Please refer the below code changes. 
 
XAML 
  <Syncfusion:SfDataGrid x:Name="SfDataGrid1" HorizontalAlignment="Left" Margin="0,50,0,0" DataContext="{DynamicResource ViewModelKey}" 
                               VerticalAlignment="Top" AutoGenerateColumns="False" ItemsSource="{Binding Favorites}"> 
            <Syncfusion:SfDataGrid.Columns> 
                <Syncfusion:GridTextColumn x:Name="nameColumn" MappingName="Name" HeaderText="Name"/> 
                <Syncfusion:GridTextColumn x:Name="colorColumn" MappingName="Color" HeaderText="Color"/> 
            </Syncfusion:SfDataGrid.Columns> 
        </Syncfusion:SfDataGrid> 
 
For your reference we have attached the tested video and ItemsSource binding properly in SfDataGrid. 
 
Video Link: ObservableCollection 
 
Regards, 
Srinivasan 
 




CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;