I feel like I've missed something obvious, but when creating a custom control in Silverlight I can declare properties as public and they will be exposed when making XAML declarations, so I can easily do something like this:
public class MyControl : UserControl
{
public string Title {get; set;}
}
And this:
<local:MyControl Title="Hello World" />
However properties are not always simple types, I may have a complex property, like a list that defines 1 or more columns and identifies a field to be bound to it. With existing controls the syntax for defining these values in XAML is straight forward:
<local:MyControl Title="People List">
<local:MyControl.Columns>
<local:MyControlColumn Heading="Column 1" Binding="{Binding Name}" />
<local:MyControlColumn Heading="Column 2" Binding="{Binding Age}" />
</local:MyControl.Columns>
</local:MyControl>
However I'm at a loss of how to make this work in the class definition:
public class MyControl : UserControl
{
public string Title {get; set;}
public IEnumerable ItemSource {get; set;}
public ObservableCollection<MyControlColumn> Columns {get; set;} // ?
}
public class MyControlColumn
{
public string Heading {get; set;}
public ??? Binding {get; set;} // ?
}
Can anyone point me in the right direction for making exposed list and binding properties?