This post contains three questions really, so I'll try and be as succinct as possible.
I have a class (MyClass) derived from UserControl containing a DataGrid with a Column defined as thus:
<xcdg:Column FieldName="Contact" ForeignKeyConfiguration="{StaticResource contactForeignKeyConfiguration}" />
The ForeignKeyConfiguration is defined in my Resources as thus:
<xcdg:ForeignKeyConfiguration x:Key="contactForeignKeyConfiguration"
ItemsSource="{Binding Source={x:Static Application.Current}, Path=Contacts}"
ValuePath="ContactID" />
I then have the following property defined in my App class:
public DataTable Contacts
{
get
{
DataTable dt = new DataTable();
dt.Columns.Add("ContactID", typeof(int));
dt.Columns.Add("Contact", typeof(string));
DataRow dr = dt.NewRow();
dr["ContactID"] = 1;
dr["Contact"] = "Jason";
dt.Rows.Add(dr);
return dt;
}
}
First question
However, in a similar way to the 'Ship Via' column in the TableView example, I expected a drop-down list to appear on the cells of my DataGrid under the 'Contact' column showing one item "Jason". Instead, it showed one item "System.Data.DataRowView". This is the first question - how do I get it showing the value in the 'Contact' column of my DataTable?
Second question
Now, if I move the Contacts property into MyClass and change my ForeignKeyConfiguration to:
<xcdg:ForeignKeyConfiguration x:Key="contactForeignKeyConfiguration"
ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=Contacts}"
ValuePath="ContactID" />
...this doesn't work. The property isn't even read. How do I achieve this so that the property in my UserControl class is correctly assigned to the ItemsSource property of my Column's ForeignKeyConfiguration?
Third question
And finally, I would like the property to be of type Dictionary<int,string> rather than DataTable. Can I achieve the same auto-detection of drop-down items as with a DataTable?
Thanks for any help that you can give!
Jason
Assistant Vice President, .NET Development
Barclays Capital, UK