【发布时间】:2013-12-24 12:56:13
【问题描述】:
我正在尝试基于一些集合构建一个Pivot 系统,而不必使用代码隐藏来构建它。
我的集合是Dictionary<CategoriesEnum, List<object>>,我想将PivotItem 的标头绑定到CategoriesEnum 对象,而其内容必须绑定到相关的List<objet>。
实际上我已经能够绑定PivotItem 的标头,但我真的不能为List 做到这一点。
这是我当前的代码:
(XAML)
<phone:Pivot x:Name="pivot"
ItemsSource="{Binding Categories}">
<phone:Pivot.ItemTemplate>
<DataTemplate>
<phone:PivotItem Header="{Binding}">
<ListBox ItemsSource="{Binding Path=Objects}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</phone:PivotItem>
</DataTemplate>
</phone:Pivot.ItemTemplate>
</phone:Pivot>
(C#)
public List<Categories> Categories
{
get
{
return new List<Categories>(Dictionary.Keys);
}
}
public List<object> Objects
{
get
{
return Dictionary[(Categories)pivot.SelectedItem];
}
}
我知道Objects 属性永远不会以这种方式工作,但我不知道如何进行这种类型的绑定,我也没有在网上找到任何线索。
【问题讨论】:
-
在您进行绑定之前,列表是否已创建并填充了数据?是否列出了任何绑定错误?
-
你可以使用转换器来获取数据
-
无绑定错误,列表已满! @techloverr:我会尽快尝试,因为这听起来不错
-
@techloverr:我在
ListBox的ItemsSource中添加了Converter,但从未调用过Converter -
既然是字典,我想你想绑定到'Value'属性。
标签: c# xaml binding windows-phone-8