1

みなさん、こんにちは XAML MVVM の概念は初めてです CollectionViewSource のいくつかの概念が必要であることはわかっています GridView を使用した WinRT アプリを持っています すべてのアイテムを職業別にグループ化したい ModelView を作成しました collectionView ソースに変換する方法 Google で検索しましたが、ここに解決策はありませんコードのいくつかの部分に行きます:

  <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>
4

1 に答える 1

1

CollectionViewSourceを取得するには、ViewModel呼び出しで

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

(PeoplecollectionがObservableCollectionまたは類似のものであると想定します。これを取得したら、次を使用してグループ化できます。

groupable.GroupDescriptions.Add(new PropertyGroupDescription("Country"));
于 2013-02-19T09:52:20.700 に答える