c# - WPF GridView 中的可编辑组合框

标签 c# wpf xaml telerik

我有一个使用 MVVM 绑定(bind)到数据的 GridView。

我希望用户能够从列表中选择可用的描述或编写文本。

我还希望根据 SL 列中的值更改描述列表。

这是我的代码:

  <telerik:GridViewDataColumn Header="Description" Width="180">
      <telerik:GridViewDataColumn.CellTemplate>
          <DataTemplate>
              <TextBlock Text="{Binding Description1}"/>
          </DataTemplate>
      </telerik:GridViewDataColumn.CellTemplate>
      <telerik:GridViewDataColumn.CellEditTemplate>
          <DataTemplate>
              <telerik:RadComboBox IsEditable="True" ItemsSource="{Binding SLStandardDescriptions}" 
                                   Text="{Binding Description1,Mode=TwoWay}">
                  <i:Interaction.Triggers>
                      <i:EventTrigger EventName="DropDownOpened">
                          <i:InvokeCommandAction Command="{Binding DataContext.SLStandardDescriptionsDropDownOpenedCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
                      </i:EventTrigger>
                  </i:Interaction.Triggers>
              </telerik:RadComboBox>
          </DataTemplate>
      </telerik:GridViewDataColumn.CellEditTemplate>
  </telerik:GridViewDataColumn>

在 ViewModel 中:

private async void OnSLStandardDescriptionsDropDownOpened()
{
    if (AccDocumentItem?.SL != null)
    {
        AccDocumentItem.SLStandardDescriptions = await _uow.SLStandardDescriptions.Where(x => x.SLId == AccDocumentItem.SLId).Select(x=>x.SLStandardDescriptionTitle).ToListAsync();
    }
}

最佳答案

尝试使用这个:

<telerik:GridViewDataColumn Header="Description" Width="180">
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <telerik:RadComboBox IsEditable="True" 
                ItemsSource="{Binding SLStandardDescriptions}" 
                Text="{Binding Description1,Mode=TwoWay}"     >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="DropDownOpened">
                        <i:InvokeCommandAction Command="{Binding DataContext.SLStandardDescriptionsDropDownOpenedCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </telerik:RadComboBox>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>

</telerik:GridViewDataColumn>

关于c# - WPF GridView 中的可编辑组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48802417/

相关文章:

c# - 使用 LINQ 从 ID 引用的表中获取记录名称

c# - 如何异步检索多个网站?

wpf - 需要关于 MVVM 验证的建议

c# - 从 ViewModel 调用 View Code Behind 中的方法?

silverlight - 在 Silverlight xaml 中进行数据绑定(bind)时 append 字符串问题

c# - Windows BluetoothLeAdvertisement 不包含 Android 设备广播的服务 uuid

c# - MyList = new List<int>();有效,但 MyList.Clear();没有

wpf - 公开依赖项属性

c# - 如何构建字符串以动态访问 .resx 资源

.net - XAML 解析器如何识别 NameScopes?