C# 将轴绑定到词典
我正在尝试基于一些集合构建一个Pivot系统,而不必使用代码隐藏来构建它 我的集合是一个字典,我希望将数据透视项的标题绑定到CategoriesEnum对象,而其内容必须绑定到相关列表 实际上,我已经能够绑定数据透视项的标题,但我真的不能为列表绑定。 以下是我当前的代码: XAML CC# 将轴绑定到词典,c#,xaml,binding,windows-phone-8,C#,Xaml,Binding,Windows Phone 8,我正在尝试基于一些集合构建一个Pivot系统,而不必使用代码隐藏来构建它 我的集合是一个字典,我希望将数据透视项的标题绑定到CategoriesEnum对象,而其内容必须绑定到相关列表 实际上,我已经能够绑定数据透视项的标题,但我真的不能为列表绑定。 以下是我当前的代码: XAML C 我知道Objects属性永远不会以这种方式工作,但我不知道如何进行这种类型的绑定,我也没有在网上找到任何线索。将ItemsSource绑定到字典会枚举KeyValuePairs,从中可以绑定到Key和Value属
我知道Objects属性永远不会以这种方式工作,但我不知道如何进行这种类型的绑定,我也没有在网上找到任何线索。将ItemsSource绑定到字典会枚举KeyValuePairs,从中可以绑定到Key和Value属性。假设字典中的键是string,值是enumerables IList: XAML C
在进行绑定之前,列表是否已创建并填充了数据?您是否列出了任何绑定错误?您可以使用converter获取数据无绑定错误,并且列表已填充@techloverr:我会尽快尝试,因为它听起来很不错idea@techloverr:我已将转换器添加到ListBox的ItemsSource,但该转换器从未被调用,因为它是字典,我认为您希望绑定到“Value”属性。
<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>
public List<Categories> Categories
{
get
{
return new List<Categories>(Dictionary.Keys);
}
}
public List<object> Objects
{
get
{
return Dictionary[(Categories)pivot.SelectedItem];
}
}
<phone:Pivot x:Name="pivot" ItemsSource="{Binding MyDictionary}">
<phone:Pivot.ItemTemplate>
<DataTemplate>
<phone:PivotItem Header="{Binding Key}">
<ListBox ItemsSource="{Binding Value}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding MyName}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</phone:PivotItem>
</DataTemplate>
</phone:Pivot.ItemTemplate>
</phone:Pivot>
public IDictionary<string, IList<MyObject>> MyDictionary { get; set; }
public class MyObject
{
public string MyName { get; set; }
}