2013-02-19 47 views
1

大家好我是新來的XAML MVVM的概念,我知道需要我幾個CollectionViewSource的概念我有一個WinRT的應用程序與GridView我想按專業分組每個項目我創建了一個ModelView如何轉換爲collectionView源我搜索谷歌,但在這裏沒有辦法解決前進中的代碼的幾個部分:創建CollectionViewSource

<Page.Resources> 
      <DataTemplate x:Key="MyDataTemplate"> 
       <Border > 

        <Grid Background="DodgerBlue" Height="150" Width="200" Margin="0,-7,-7,0" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False"> 
         <StackPanel VerticalAlignment="Bottom"> 
          <StackPanel.Background> 
           <SolidColorBrush Color="Black" Opacity=".25"/> 
          </StackPanel.Background> 
          <TextBlock Text="{Binding Name}"/> 
          <TextBlock Text="{Binding Profession}"/> 
          <TextBlock Text="{Binding Age}"/> 
         </StackPanel> 
        </Grid> 
       </Border> 
      </DataTemplate> 
      <ItemsPanelTemplate x:Key="ItemsPanelTemplate1"> 
       <VariableSizedWrapGrid x:Name="gridviewVariableSized" MaximumRowsOrColumns="4" Orientation="Vertical" /> 
      </ItemsPanelTemplate> 

     </Page.Resources> 
<Page.DataContext> 
     <ModelView:PeopleCollection/> 
    </Page.DataContext> 

回答

1

要獲得CollectionViewSource,在您的視圖模型調用

var groupable = CollectionViewSource.GetDefaultView(this.PeopleCollection); 

(假設Peoplecollection是一個ObservableCollection或類似的東西。一旦你有這樣的你。可以組usi ng

groupable.GroupDescriptions.Add(new PropertyGroupDescription("Country")); 
+0

請問這個答案是指WinRT類嗎? – Jon 2013-02-19 09:54:52