我有一个使用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();
}
}
答案 0 :(得分:3)
尝试使用:
<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>