This is a migrated thread and some comments may be shown as answers.

RadDataGrid: Binding CollectionViewSource

3 Answers 104 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andi
Top achievements
Rank 1
Andi asked on 26 Nov 2013, 10:36 PM
Hi there,
I migrated a Windows 8 project to Windows 8.1.
There I was using a RadDataGrid where I was binding a CollectionViewSource to its ItemSource property. 
<telerikGrid:RadDataGrid x:Name="sumBlockGrid"
   ItemsSource="{Binding Source={StaticResource accountBalancesViewSource}}"
    
This worked in Windows 8.

Now I get an error "Specified data source not supported".
It seems that the Windows 8.1 version of RadDataGrid has changed at this point and that the old version also accepted CollectionViewSources.This was convenient to switch between design time data:
<CollectionViewSource
    x:Name="accountBalancesViewSource"
    Source="{Binding AccountBalances}"
    ItemsPath="Items" IsSourceGrouped="False"
    d:Source="{Binding AccountBalances, Source={d:DesignInstance Type=data:SampleData, IsDesignTimeCreatable=True}}" />

Is there a WorkAround or do I have to use code behind to bind my data?

Thanks,
Andi

3 Answers, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 29 Nov 2013, 05:43 PM
Hi Andi,

I admit that there is a bug that causes the RadDataGrid to raise an exception. I will forward this information to our development team to further investigate what might cause this. 
For now, I can suggest a temporary workaround. As it seems that when the RadDataGrid binds to the CollectionViewSource, the grid cannot handle the current state of the CollectionViewSource.View object, so I suggest that you use a class that derives from the FrameworkElement and implements two dependency properties. The first will be bound to the CollectionViewSource.View, and when it receives a new value it will pass the object as an IEnumerable to the second dependency property. Thus, the RadDataGrid can be bound to the second property and it will handle the IEnumerable correctly.
For your convenience, I have attached a project that shows how to achieve this.

Let me know if this works for you. Also, I have updated your Telerik points for your valuable feedback.

Regards,
Ivaylo Gergov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Andi
Top achievements
Rank 1
answered on 02 Dec 2013, 08:58 AM
Hi Gregov,
your solution works - but the sample data is not displayed in the designer.
I found the following solution (without a CustomItem):  
I am binding directly the ObservableCollection.
(Note:I also see no design time data)

The Binding:
<telerikGrid:RadDataGrid x:Name="sumBlockGrid"
     ItemsSource="{Binding Path=AccountBalances}"

The object of my DataContext has:
public ObservableCollection<AccountBalanceDto> AccountBalances { get; private set; }

Any further ideas?
Andi
0
Ivaylo Gergov
Telerik team
answered on 02 Dec 2013, 10:14 AM
Hi Andi,

At this point we do not have any other suggestions. I will contact you as soon as we have more information regarding this problem.



Regards,
Ivaylo Gergov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Grid for XAML
Asked by
Andi
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Andi
Top achievements
Rank 1
Share this question
or