I am having some trouble with binding a list box in WPF with Caliburn Micro. I've got a Login View that looks like this:
<Button x:Name="Login" Click="Login_Click" Canvas.Left="200" Canvas.Top="360" Content="Login" FontSize="20" Height="40" Width="80"/>
<ListBox x:Name="DataBox1" Canvas.Left="330" Canvas.Top="332" Height="93" Width="130" />
The Login View Model code:
public IQueryable<String> forenameOne;
public void Login()
{
//var conductor = this.Parent as IConductor;
//conductor.ActivateItem(new AdministrationViewModel());
using (TableClassesDataContext db = new TableClassesDataContext())
{
var userdetails = from v in db.GetTable<PlannerUser>()
select v.Forename;
MessageBox.Show("User details: " + userdetails.ToString());
DataBox1 = userdetails;
}
}
Code behind view (what I want to do in ViewModel):
DataBox1.ItemsSource = userdetails;
I can get it to work when I do it in code behind View (.xaml.cs) but not from the Login View Model. This is just the start of this application and data won't need to be displayed on this screen, but I need to figure this out for when it is needed. I've tried various things, like setting the binding property of the listbox, to no avail. I need it to display the forename from the database when login is clicked, but it doesn't seem to want to work and I can't find how it should work online.
Thanks in advance!