Add different types or UserControl in ItemControl

70 views Asked by At

I am using an ItemControl in my xaml code and it's itemsource is bound to a list of myCustomUserControl.

I use Catel MVVM framework

My question is : I have now a second type of UserControl with it's own view and viewmodel. Is it possible to bind the itemsource of my Itemcontrol with two types of UserControls ? If it's possible, how does i specify in the itemControl dataTemplate the different possible Views of my two usercontrols.

Here is the code of my ItemControl :

<ItemsControl ItemsSource="{Binding myCustomUserControl}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
            <Views:myCustomUserControlView/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>

Thank you !

0

There are 0 answers