绑定到ListBox中的ListBox

编程入门 行业动态 更新时间:2024-10-20 16:05:49
本文介绍了绑定到ListBox中的ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我试图将一个小的电视指南应用程序放在一起,但是绑定到查询的信息时遇到了一些麻烦. 计划要有一个ListBox,其中每个项目都包含一个图像和/或频道名称,以及另一个ListBox(仅用于确认,ListBox项目中的一个ListBox),其中将包含该频道的所有即将上映的电视节目. br/> 我发现了与我想做的事情非常相似的事情,但是我似乎无法使它正常工作,有人能看到我做错了吗?

Hello All, I am trying to put together a small TV Guide Application and I am having some trouble Binding to the queried information. The plan is to have a ListBox where each Item contain an Image and/or the Channel Name and another ListBox (just to confirm, that''s a ListBox in a ListBox Item) which will contain all the upcoming TV programs for that channel. I found something very similar to what I''d like to do but I can''t seem to get it to work, can anybody see what I''m doing wrong?

<ListBox x:Name="TVGuideListBox"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <DockPanel> <TextBlock MinWidth="160" Text="{Binding Path=Channel.ChannelName}" DockPanel.Dock="Left" /> <ListBox ItemsSource="{Binding Path=Program}" BorderThickness="0"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" IsItemsHost="True"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Title}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </DockPanel> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>

namespace TVGuide { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> /// public partial class MainWindow : Window { TVDataContext TVDC = new TVDataContext(); public MainWindow() { InitializeComponent(); LoadChannels(); } public class Channel { public string ChannelName { get; set; } public string ChannelID { get; set; } } public class Program { public string StartTime { get; set; } public string StopTime { get; set; } public string ChannelID { get; set; } public string Title { get; set; } public string Description { get; set; } } public class exChannels { public List<Channel> ChannelInfo { get; set; } public List<Program> ProgramInfo { get; set; } public exChannels(List<Channel> ch, List<Program> prog) { ChannelInfo = ch; ProgramInfo = prog; } } public void LoadChannels() { DateTime time = DateTime.Now.ToUniversalTime(); // Use current time string format = "yyyy MM d HH mm"; // Use this format string timevalue2 = Regex.Replace(time.ToString(format), @"[\D]", ""); decimal currenttime_dec = (Convert.ToDecimal(timevalue2) * 100); XDocument xmlDoc = XDocument.Load(@"C:\iceguide.xml"); var ChannelsQuery = (from s in TVDC.tv_CHANNELs orderby s.channel_ID select new Channel { ChannelName = s.channel_NAME, ChannelID = s.guide_ID }).ToList<Channel>(); foreach (var s in ChannelsQuery) { var ProgramQuery = (from c in xmlDoc.Descendants("programme") where c.Attribute("channel").Value == s.ChannelID select new Program { StartTime = c.Attribute("start").Value, StopTime = c.Attribute("stop").Value, ChannelID = c.Attribute("channel").Value, Title = c.Element("title").Value, Description = c.Element("desc").Value }).ToList<Program>(); exChannels exChannel = new exChannels(ChannelsQuery, ProgramQuery); TVGuideListBox.Items.Add(exChannel); } } } }

我在树错树上吠叫吗?任何帮助,甚至是正确方向的帮助,都将不胜感激. 预先谢谢您, 亲切的问候, Alex

Am I barking up the wrong tree? Any help or even a kick in the right direction would be greatly appreciated. Thank you in advance, Kind Regards, Alex

推荐答案

与其尝试将ListBox放在另一个ListBox中,不如将其按Channel分组在一个ListBox中.搜索如何使用CollectionViewSource对ListBox中的项目进行分组. 列表框分组,排序,小计和可折叠区域 [ ^ ]是一个好的开始.祝你好运! Instead of tryin to put a ListBox inside another ListBox, you should rather Group the items in one ListBox by Channel. Search for how to group items in a ListBox using a CollectionViewSource. ListBox Grouping, Sorting, Subtotals and Collapsible Regions[^] is agood start. Good luck!

更多推荐

绑定到ListBox中的ListBox

本文发布于:2023-11-06 14:16:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563918.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   ListBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!