I'd like to create WPF control which consists of few another controls. The main problem is how implement choosing right control depending on Model's type?
<MyControl>
<!-- if DataContext.GetType() == Type1 -->
<Control1 DataContext = {Binding}/>
<!-- if DataContext.GetType() == Type2 -->
<Control2 DataContext = {Binding}>
</MyControl>
How can i implement and design it well? My idea was to put there something like...
Control CreateControl(object dataContext) {
if (dataContext.GetType() == TYpe1)
return new Control1() {DataContext = dataContext}
if (dataContext.GetType() == TYpe2)
return new Control2() {DataContext = dataContext}
}
But i don't know how can i invoke such method, which returns Control inside XAML...