I actually created an example application for something completely different, but then I tried to do this:
I have a collection of Movies . I will have a list box in which all the films will be shown. However, the list box provides them in the form of buttons so that you can click on the button and play the movie.
The code:
<StackPanel DockPanel.Dock="Top"> <ListBox ItemsSource="{Binding Movies}" SelectedItem="{Binding Path=SelectedMovie}"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel IsItemsHost="True" Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <Button Content="{Binding Title}" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PlayMovieCommand}" CommandParameter="{Binding Id}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel>
Then I thought about adding one button to the end, with the text "Add", and when I click on this button, I can add a new movie.
I did not find a solution for this. When searching the Internet, I found HierarchicalDataTemplate and CompositeCollection ; both at first looked promising, but I was not able to get it to work as I want. I also thought about MultiBinding , but again I seem to fail.
So, I think my question is:
How to add one added button to my movie collection?
Or more general: How can I add several sources / collections of data of different types to the list?
source share