我正在尝试绑定词典>列表视图。将标题设置为Idictionary的键,将约会对象列表设置为项目。但数据没有受到限制。
字符串(key)需要与header元素绑定,内部列表列表包含该header下的对象。
我该如何解决这个问题?
<ListView ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollMode="Auto" ScrollViewer.HorizontalScrollMode="Auto"
ItemsSource="{Binding Source={StaticResource EventsObj}}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Textblock Text="{Binding EventsObj.Value.UserName}"/>
<Textblock Text="{Binding EventsObj.Value.VisitorFor}"/>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.HeaderTemplate>
<DataTemplate>
<Grid Margin="5,10,0,10" Background="Black">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="68*"/>
<ColumnDefinition Width="21*"/>
</Grid.ColumnDefinitions>
<TextBlock Foreground="White" Text="{Binding EventsObj.Key}">
</TextBlock>
</Grid>
</DataTemplate>
</ListView.HeaderTemplate>
C#中的对象是
public class Appointment
{
public Dictionary<DateTime, List<Appointments>> Data {get; set;}
}
public class Appointments
{
public string UserName {get; set;}
public string VisitorFor {get; set;}
}
List<Appointments> Datas = new List<Appointments>();
Datas = new List<Aprio.Appointments>();
Datas.Add(new Appointments { UserName = "Pradeep", VisitorFor = "John Sam" });
Datas.Add(new Appointments { UserName = "Danny", VisitorFor = "John Sam" });
Datas.Add(new Appointments { UserName = "Ram", VisitorFor = "John Sam" });
Datas.Add(new Appointments { UserName = "Siva", VisitorFor = "John Sam" });
Datas.Add(new Appointments { UserName = "Ragu", VisitorFor = "John Sam" });
this.Appointment.Add("John", Datas);
List<Appointments> Datas2 = new List<Appointments>();
Datas2 = new List<Appointments>();
Datas2.Add(new Appointments { UserName = "Guru", VisitorFor = "Sam Hilferg" });
Datas2.Add(new Appointments { UserName = "Jack", VisitorFor = "Sam Hilferg" });
Datas2.Add(new Appointments { UserName = "Bob", VisitorFor = "Sam Hilferg" });
this.Appointment.Add("Sam", Datas2);
答案 0 :(得分:0)
更改ListView ItemTemplate。试试这个!
<ListView.ItemTemplate>
<DataTemplate>
<ListView DataContext="{Binding EventsObj.Value}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<Textblock Text="{Binding UserName}"/>
<Textblock Text="{Binding VisitorFor}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</ListView.ItemTemplate>
答案 1 :(得分:0)
我已将标题移到右侧。在MSDN中找到了这个答案。它对我有用。
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid GroupHeaderPlacement="Left"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>