Trouble using CollectionViewSource in Silverlight

Posted by Johnny on Stack Overflow See other posts from Stack Overflow or by Johnny
Published on 2009-11-30T23:20:43Z Indexed on 2010/05/17 16:00 UTC
Read the original article Hit count: 252

Hi, I having some trouble when implementing the CollectionViewSource in silverlight. I'm new in this topic, so basically I've been following what I find searching through the web. Here's what I've been trying to do so far.

I'm creating a CollectionViewSource in the resources tag:

     <CollectionViewSource x:Key="TestCVS">
           <scm:SortDescription PropertyName="Value" Direction="Ascending" />

Then I'm binding my TestCVS in a HierarchicalDataTemplate:

<common:HierarchicalDataTemplate ItemsSource="{Binding Source={StaticResource TestCVS}}">
      <Border BorderBrush="#FF464646" BorderThickness="1" CornerRadius="3" Padding="5">
            <RowDefinition />
            <RowDefinition />
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
            <TextBlock  TextWrapping="Wrap" Text="{Binding MyClassField}"/>

Now, in the code behind I'm assigning the Source for the TestCVS in a property, like this:

private ObservableCollection<MyClass> _MyClass;
public ObservableCollection<MyClass> MyClass    
   get { return _MyClass; }
      var testCVS = (this.Resources["TestCVS"] as CollectionViewSource);

      if (testCVS != null)
        testCVS.Source = value;

After testing this I realize that the information is not showing on screen and I don't really know why, can anyone help me on this matter?

Hope this makes any sense, thanks in advance!

© Stack Overflow or respective owner

Related posts about collectionviewsource

Related posts about Silverlight