caliburn micro master detail
I have looked at all the Caliburn Micro stuff I can find and I think I'm
simply confusing myself. I put together a simple sample as a test.
Model = Person.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfTestApp
{
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
PersonView.xaml
<UserControl x:Class="WpfTestApp.PersonView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FirstName}" />
<TextBlock Text="{Binding LastName}" />
</StackPanel>
</Grid>
</UserControl>
ShellViewModel.cs
using Caliburn.Micro;
using System.ComponentModel.Composition;
namespace WpfTestApp {
[Export(typeof(IShell))]
public class ShellViewModel : PropertyChangedBase, IShell
{
public BindableCollection<PersonViewModel> Items { get; set; }
public ShellViewModel()
{
Items = new BindableCollection<PersonViewModel> {
new PersonViewModel(new Person { FirstName="Bart",
LastName="Simpson" }),
new PersonViewModel(new Person { FirstName="Lisa",
LastName="Simpson" }),
new PersonViewModel(new Person { FirstName="Homer",
LastName="Simpson" }),
new PersonViewModel(new Person { FirstName="Marge",
LastName="Simpson" }),
new PersonViewModel(new Person { FirstName="Maggie",
LastName="Simpson" })
};
}
}
}
ShellView.xaml
<Window x:Class="WpfTestApp.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.caliburnproject.org">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel>
<ListBox x:Name="Items"/>
</StackPanel>
<ContentControl cal:View.Model="{Binding SelectedItem,
Mode=TwoWay}" Grid.Row="1" />
</Grid>
</Window>
I am using the MEFBootstrapper as per the Caliburn Micro documentation.
1) Why is that when I select an item in the ListBox, nothing appears in
the ContentControl. I am obviously missing something but I thought
SelectedItem was hooked up by the conventions. I've tried using
x:Name="ActiveItem" and that did not work either?
2) How does this work if my ShellViewModel.cs contained a
BindableCollection of Person instead of PersonViewModel?
3) Can I name the BindableCollection something other than Items (Yes - I
know Items is a convention of Caliburn Micro)?
Regards Alan
No comments:
Post a Comment