gpt4 book ai didi

wpf - 应用于所有组合框选定项目的项目

转载 作者:行者123 更新时间:2023-12-03 10:45:06 46 4
gpt4 key购买 nike

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

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

  • 组合框绑定(bind)到 Service 类的 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>

    这是数据网格行组合框绑定(bind):
    <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

    非常感谢

    最佳答案

    如果我没有误解您的问题,您可以在 ApplyCommand 操作中设置服务(绑定(bind)到 SelectedValue)

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

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

    关于wpf - 应用于所有组合框选定项目的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28955501/

    46 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com