【发布时间】:2014-08-18 09:51:31
【问题描述】:
我在商店应用中的绑定列表有问题。
public class Category
{
public Category(int id, string name)
{
this.ID = id;
this.Name = name;
}
public int ID { get; set; }
public string Name { get; set; }
}
我创建了 ColllecionViewSource 和 GridView
<CollectionViewSource x:Name="CategoriesViewSource" IsSourceGrouped="True"/>
<GridView ItemsSource="{Binding Source={StaticResource CategoriesViewSource}}" >
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}"></TextBlock>
<TextBlock Text="{Binding ID}"></TextBlock>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
在我的页面的构造函数中,我将类别列表添加到 CollectionViewSource
public HubPage()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
List<Category> test = new List<Category>();
test.Add(new Category(1, "two"));
CategoriesViewSource.Source = test;
}
但它不起作用......我做错了什么?
【问题讨论】:
-
CollectionViewSource 位于何处?资源不应该在资源部分并使用 x:Key 属性作为静态资源吗?
-
CollectionViewSource 在 Page.Resources 部分。我不知道你说的 x:Key 是什么意思,CollectionViewSource 有这个属性
-
StaticResource 通常通过 x:Key 属性找到。 ResourceDictionary 使用它(x:Key) 来索引其内容。
标签: c# xaml binding microsoft-metro store