【发布时间】:2015-03-10 03:07:43
【问题描述】:
我想有一个功能将所选项目应用于数据网格中的所有组合框。目前我所拥有的:
- 组合框用于选择要应用于数据网格中所有组合框的项目。这已放在标题部分
- 执行“全部应用”命令的按钮
- 每行数据网格中的组合框。
组合框绑定到服务类的 ObservableCollection :
public ObservableCollection<Services> ServiceList
{
get
{
return serviceList;
}
set
{
this.serviceList = value;
RaisePropertyChanged("ServiceList");
}
}
这就是我应用命令在 XAML 中执行所述功能的方式:
<StackPanel Name="stackPanel2"
Grid.Row="1"
Grid.Column="1"
Width="335"
Height="26"
Margin="3,8,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Orientation="Horizontal">
<ComboBox Name="comboBox1"
Width="120"
Height="23"
DisplayMemberPath="DESCRIPTION"
ItemsSource="{Binding ServiceList}"
SelectedItem="{Binding SelectedServiceAll,Mode=TwoWay}"
/>
<Button Content="Apply to all"
Command="{Binding CommandApplyAll}"
CommandParameter="AllService"
>
</Button>
</StackPanel>
这是数据网格行组合框绑定:
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="comboBoxService"
Width="120"
Height="23"
DisplayMemberPath="DESCRIPTION"
ItemsSource="{Binding Path=ServiceList}"
SelectedValue="{Binding Path=SERVICE,
UpdateSourceTrigger=PropertyChanged}"
/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
我是否应该使用已在标题部分选择但不知道如何实现的更新数据网格中组合框的数据源(ObservableCollection ServiceList)。
注意:此应用程序应用了 MVVM
非常感谢
【问题讨论】:
-
Header ComboBox的ItemsSource和DataGrid的Comboboxes一样吗?
-
Header ComboBox itemsource 来自静态列表,而 Data Grid Row ComboBox 来自 ObservableCollection
-
@ethicallogics -> 编辑:ata Grid Row ComboBox 与 Header ComboBox itemsource 相同