【发布时间】:2020-06-29 21:55:18
【问题描述】:
我有一个 ListView,我在其中放置了一些 ComboBox,如下所示:
<ListView x:Name="ListViewCategories" SelectedItem="{Binding SelectedCategory}" ItemsSource="{Binding ListCategoryPart}" SelectionChanged="ListViewCategories_SelectionChanged">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header ="{x:Static p:Resources.Machine}" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox
ItemsSource="{Binding ListCutMachines}"
SelectedValuePath="ID"
SelectedValue="{Binding DefaultCutMachine, UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Name" Width="100"
/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
DefaultCutMachine 是我的对象 CategoryPart(ListView 中列出的项目)的一部分。
但我想要的不是从我的对象中获取 Combobox ItemsSource,而是从我的 ViewModel 中获取。
如何绑定我的所有项目组合框 ItemsSource,而不是从项目,而是从我的 ViewModel?(我阅读了“BindingContext”,但没有找到如何在 ComboBox ItemsSource 上执行此操作)
【问题讨论】: