I'd like to use Caliburn.Micro conventions for the Accordion control from Silverlight and WPF Toolkits:
View:
<Grid Background="White">
<Controls:Accordion x:Name="Items"/>
</Grid>
ViewModel:
public class ShellViewModel : IShell
{
public ShellViewModel()
{
Items = new List<AccItemViewModel>
{
new AccItemViewModel
{
DisplayName = "header one",
Content = "content one"
},
new AccItemViewModel
{
DisplayName = "header two",
Content = "content two"
},
};
}
public IEnumerable<IScreen> Items { get; set; }
public class AccItemViewModel : Screen
{
public string Content { get; set; }
}
By default, Caliburn binds elements in Accordion's ItemsSource into AccordionItem headers:
I have added the convention for the Accordion's ContentTemplate:
private void AddCustomConventions()
{
ConventionManager.AddElementConvention<Accordion>
(Accordion.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
.ApplyBinding =
(viewModelType, path, property, element, convention) =>
{
if (ConventionManager
.GetElementConvention(typeof(ItemsControl))
.ApplyBinding(viewModelType, path, property,
element, convention))
{
element.SetValue(Accordion.ContentTemplateProperty,
ConventionManager.DefaultItemTemplate);
return true;
}
return false;
};
}
which achieved the following:
but I'd like to either bind the AccordionItem's header to DisplayName of the AccItemViewModel(IScreen) or have a Header view model property on AccItemViewModel. AccordionItem has HeaderProperty and HeaderTemplateProperty, but I can't figure out how to apply conventions to these.