【发布时间】:2014-08-20 19:48:44
【问题描述】:
我实际上是在为完全不同的东西设置一个示例应用程序,但后来我尝试这样做:
我收藏了Movies。我将有一个显示所有电影的列表框。但是,列表框将它们作为按钮提供,以便您可以单击按钮并播放电影。
代码是:
<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>
然后我想在末尾添加一个按钮,带有文本“添加”,当我单击该按钮时,我可以添加一个新电影。
我找不到提供此功能的解决方案。在网上搜索时,我发现了HierarchicalDataTemplate 和CompositeCollection;起初看起来都很有希望,但我没能按我的意愿工作。我也在想MultiBinding,但我似乎又失败了。
所以,我想我的问题是:
如何将单个添加按钮添加到我的电影收藏中?
或更通用的: 如何将多个不同类型的数据源/集合添加到列表框中?
【问题讨论】:
标签: wpf listbox itemssource multibinding