2013-02-24 45 views
0

我使用ItemsPage模板在vs 2012中創建了一個項目。CollectionViewSource的源被初始化了嗎?

<!-- Collection of items displayed by this page --> 
    <CollectionViewSource 
     x:Name="itemsViewSource" 
     Source="{Binding Items}"/> 

這裏{Binding Items}是什麼意思?我在Windows Store項目的ItemsPage中看到它。新的ItemsPage有一個基類Common.LayoutAwarePage,其中DefaultViewModel被定義爲指向IMap集合。這個集合沒有任何Items屬性,所以Source如何指向Items?

感謝 Kajal

回答

1

,如果你在代碼中LoadState向後看,你會看到:

protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) 
{ 
    // TODO: Create an appropriate data model for your problem domain to replace the sample data 
    var sampleDataGroups = SampleDataSource.GetGroups((String)navigationParameter); 
    this.DefaultViewModel["Items"] = sampleDataGroups; 
} 

這裏DefaultViewModel的關鍵是「項目」和相匹配的CollectionViewSource結合。

「Items」集合的每個元素都是SampleDataGroup,然後在模板中稍後綁定到GridView項目。

+0

謝謝。答案很有用。 :) – 2013-02-28 08:00:44