I would like to use a WrapPanel. I have a ObservableCollection with ViewModels which all have its own view. Is there a way to use DataTemplates and use multiple views ?
This is what I am doing right now:
<DataTemplate x:Key="ProjectInfoDetailTemplate"> <!-- DataType="{x:Type viewModels:ProjectInfoViewModel} -->
<views:ProjectInfoView MouseLeftButtonDown="ProjectInfoView_MouseLeftButtonDown"/>
</DataTemplate>
<ItemsControl Grid.Row="1" Grid.Column="0"
ItemsSource="{Binding AllProjects}"
ItemTemplate="{StaticResource ProjectInfoDetailTemplate}" Margin="0,15,0,0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel>
<WrapPanel.Resources>
<Style TargetType="{x:Type views:ProjectInfoView}">
<Setter Property="Margin" Value="10" />
</Style>
</WrapPanel.Resources>
</WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
But each item in the observableCollection AllProjects needs an own view.
How can you do this ?
Thanks!!
You can use ItemTemplateSelector to provide correct templates for each item. Or you can create DataTemplates without x:Key but with TargetType set and don’t specify ItemTemplate on your ItemsControl. This way wpf will find correct DataTemplate itself.