I've created two UserControls, the first of which displays a list of objects, the second of which displays details about an object that is selected from the first. I've created a dependency property on the first control and am binding each UserControl to an object declared in my Resources collection. I've seen blog posts describing this, but cannot seem to get it to work. I am getting a XamlParseException. The funny thing is the exception only occurs when I set the binding Mode=TwoWay on my first UserControls. Here's the code...
Page.xaml
<UserControl.Resources>
<local:Item x:Key="SelectedItem" />
</UserControl.Resources>
...
<controls:ItemList
SelectedItem="{Binding Mode=TwoWay, Source={StaticResource SelectedItem}}">
</controls:ItemList >
...
<controls:ItemDetails
DataContext="{Binding Source={StaticResource SelectedItem}}">
</controls:ItemDetails>
ItemList.xaml.cs
public partial class ItemList: UserControl
{
public ItemList()
{
InitializeComponent();
}
public static readonly DependencyProperty SelectedItemProperty =
DependencyProperty.Register("SelectedItem", typeof(Item), typeof(ItemList), new PropertyMetadata(new Item()));
public Item SelectedItem
{
get { return (Item )GetValue(SelectedItemProperty ); }
set { SetValue(SelectedItemProperty , value); }
}
Any suggestions are welcome!