Silverlight GridViewComboBoxColumn绑定命令与MVVM不起作用

时间:2011-12-17 09:21:04

标签: silverlight binding mvvm telerik command

我正在尝试从GridViewColumn运行命令,RadGridView绑定到我的ViewModel。下面的代码运行命令,但是当我从ComboBox中选择一个值时,它会立即保存行,而不允许我先对其他单元格进行更改。无论我是否将命令绑定到RADComboBox,都会发生此行为。如果我取消命令,仍然会发生。

XAML:

<telerik:RadGridView x:Name="GV1"
                             ItemsSource="{Binding Path=Material}"
                             AutoGenerateColumns="False"
                             IsReadOnly="{Binding IsGridReadOnly}"
                                          ShowGroupPanel="False" 
                             VerticalAlignment="Top"
                             HorizontalAlignment="Center"
                            RowDetailsVisibilityMode="VisibleWhenSelected">
       <i:Interaction.Triggers>
          <i:EventTrigger EventName="RowEditEnded">
                <cmd:EventToCommand Command="{Binding RowEditEndedCommand}"
                                                  PassEventArgsToCommand="True" />
          </i:EventTrigger>
             <i:EventTrigger EventName="CancelRowEdit">
                <cmd:EventToCommand Command="{Binding CancelEditCommand}" />
             </i:EventTrigger>
          </i:Interaction.Triggers>
<telerik:RadGridView.Columns>
<telerik:GridViewColumn Header="Material Code">
                <telerik:GridViewColumn.CellEditTemplate>
                   <DataTemplate>
                      <telerik:RadComboBox ItemsSource="{Binding DataSource.AllMaterials, Source={StaticResource DCP}}"
                                              DisplayMemberPath="Code"
                                              SelectedValuePath="Code"
                                              SelectedValue="{Binding Path=MaterialCode, Mode=TwoWay}"
                                              IsEnabled="{Binding Path=IsMaterialEditable, Mode=TwoWay}" 
                                              Command="{Binding DataSource.MaterialCodeChangedCommand, Source={StaticResource DCP}}"/>
                   </DataTemplate>
                   </telerik:GridViewColumn.CellEditTemplate>
                <telerik:GridViewColumn.CellTemplate>
                   <DataTemplate>
                      <TextBlock Text="{Binding MaterialCode}" />
                   </DataTemplate>
                </telerik:GridViewColumn.CellTemplate>
             </telerik:GridViewColumn>
    <!--7 Other Columns here-->
</telerik:RadGridView.Columns>
    </telerik:RadGridView>

背后的代码

public RelayCommand MaterialCodeChangedCommand { get; private set; }
//IN Constructor
this.MaterialTypeChangedCommand = new RelayCommand(MaterialTypeChange);

private void MaterialCodeChange()
  {
     //Command code here
  }

当我从CellEditTemplate中取出ComboBox并尝试使用GridViewComboBox时,我无法弄清楚如何使绑定工作,但它不会通过选择下拉来触发RowEditEnded以便部分正常使用此代码:

<telerik:GridViewComboBoxColumn Header="Material Type" 
                                                  ItemsSource="{Binding DataSource.AllTypeCodes, Source={StaticResource DCP}}"
                                                  SelectedValueMemberPath="Code"
                                                  DataMemberBinding="{Binding Path=MaterialType, Mode=TwoWay}"
                                                  DisplayMemberPath="Display">
                    <i:Interaction.Triggers>
                       <i:EventTrigger EventName="SelectionChanged">
                          <i:InvokeCommandAction Command="{Binding DataSource.MaterialTypeChangedCommand, Source={StaticResource DCP}}"/>
                       </i:EventTrigger>
                    </i:Interaction.Triggers>
                 </telerik:GridViewComboBoxColumn>

如果不清楚请告诉我,现在已经很晚了,我可能也不清楚。谢谢你尽你所能的帮助。我应该注意,在CellEditTemplate中设置时,RowEditEnded在我的应用程序中的其他下拉列表中也是如此。转换为GridViewComboBoxCOlumn可解决该问题,但随后解决了绑定问题......

0 个答案:

没有答案