【问题标题】:Editable Combobox in WPF GridViewWPF GridView 中的可编辑组合框
【发布时间】:2018-02-15 07:59:46
【问题描述】:

我有一个使用 MVVM 绑定到数据的 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();
    }
}

【问题讨论】:

    标签: c# wpf xaml telerik


    【解决方案1】:

    试试这个:

    <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>
    

    【讨论】:

    • 谢谢,这行得通,但我不想在 CellTemplate 中显示 ComboBox,我只想在 CellEditTemplate 中显示 ComboBox。
    猜你喜欢
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2011-08-13
    相关资源
    最近更新 更多