I would personally use an observable collection for my datasource. There are lots of examples out there, but essentially your code would look something like this. I haven't tested this code. Add some comments if you have any problems.
There are two main points here. One, don't load any data unless your not in design mode, (you could put and else statement and load stub POCO data if you need design support). Two, you should load your data on a seperate thread then your UI thread.
Updated
There was a couple of updates to the code. I changed the (new Thread) to using QueueUserWorkItem, I changed the AddItems method because ObservableCollection doesn't support AddRange, and I changed the spelling on IEnumerable
public class TvShowsDataSource
{
public ObservableCollection<Show> Shows { get; set; }
private void AddItems(IEnumerable<Show> shows)
{
foreach(var show in shows)
Shows.Add(show);
}
public void LoadShowsAsync(Dispatcher dispatcher)
{
ThreadPool.QueueUserWorkItem((state) =>
LoadShows(dispatcher));
}
private void LoadShows(Dispatcher dispatcher)
{
if (dispatcher == null)
throw new ArgumentNullException("dispatcher");
using (var context = new Data.TVShowDataContext())
{
var list = from show in context.Shows
select show;
dispatcher.Invoke(AddItems(list));
}
}
}
public class UserControl1
{
private readonly TvShowsDataSource tvShowsDataSource;
public UserControl1() : this(new TvShowsDataSource()) {}
public UserControl1(TvShowsDataSource tvShowsDataSource )
{
InitializeComponent();
this.tvShowsDataSource = tvShowsDataSource;
listShow.ItemsSource = tvShowsDataSource.Shows;
this.Loaded += UserControl1_Loaded;
}
public void UserControl1_Loaded(object sender, RoutedEventArgs e)
{
if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
{
tvShowsDataSource.LoadShowsAsync(this.Dispatcher);
}
}
}