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
{
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();
string format = "yyyy MM d HH mm";
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);
}
}
}
}
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