【问题标题】:Item to apply to all combo box selected item应用于所有组合框选定项目的项目
【发布时间】:2015-03-10 03:07:43
【问题描述】:

我想有一个功能将所选项目应用于数据网格中的所有组合框。目前我所拥有的:

  1. 组合框用于选择要应用于数据网格中所有组合框的项目。这已放在标题部分
  2. 执行“全部应用”命令的按钮
  3. 每行数据网格中的组合框。

组合框绑定到服务类的 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 相同

标签: wpf mvvm


【解决方案1】:

如果我没有误解您的问题,您可以像在 ApplyCommand Action 中设置 SERVICE(绑定到 SelectedValue)一样

    private void OnApplyCommand()
    {
        foreach (var item in ServiceGridDataList)
        {
            item.SERVICE = SelectedServiceAll.SERVICE;
        }
        SelectedGridService = selectedHeaderService;
        //Other apply command Action;
    }

这里的 ServiceGridDataList 是绑定到网格的 ItemsSource 的集合。

【讨论】:

  • 嗨..它通过应用这行代码来工作:ServiceGridDataList= ServiceGridDataList.Select(c => { c.SERVICE = SelectedServiceAll; return c; }).ToObservableCollection();..get from这个stackoverflow.com/questions/398871/…...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-14
  • 2011-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多