All,
I have what i think is the simplest example possible of data binding in silverlight... but clearly even that is too complicated for me :)
The XAML:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<ListBox x:Name="rblSessions">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding SessionTitle}" Foreground="Black" FontSize="30" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
List<Sessions> theSessions = makeSessions();
rblSessions.ItemsSource = theSessions;
rblSessions.DataContext = theSessions;
}
public List<Sessions> makeSessions()
{
List<Sessions> theReturn = new List<Sessions>();
for (int i = 0; i < 20; i++)
{
Sessions s = new Sessions() { SessionID = i, SessionTitle = string.Format("title{0}", i) };
theReturn.Add(s);
}
return theReturn;
}
}
public class Sessions
{
public int SessionID;
public string SessionTitle;
}
}
When I run the app, I get a listbox with 20 elements in it, but each element is empty, and only about 5 pixels tall (though I set FontSize to "30")
What am I doing wrong? Help please and thanks
/jonathan