对于没有Command属性时,怎么来达到相同的效果

控件是第三方Telerik控件  CellEditEnded事件想写成Command{Binding CellEditEndedCommand}  这样的效果如下代码

 

需要引用

System.Windows.Interactivity

 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

<telerik:RadGridView Name="LoadingGridView"
                                SelectedItem="{Binding Pkey}"        
                                Height="400"
                                AutoGenerateColumns="False"  
                                Margin="2"
                                HorizontalAlignment="Stretch"
                                sumer:StyleManager.Theme="Windows8"
                                NewRowPosition="Bottom"
                                GroupRenderMode="Flat"
                                ItemsSource="{Binding DataContext.T_PSF_Loading_Cargo1, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
                                RowIndicatorVisibility="Visible"  
                                ShowGroupPanel="False"
                                SelectionMode="Extended"    
                                    >
//对于一些属性,来Command事件,我们可以用以下这种方式
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="CellEditEnded">//事件名称
                                            <i:InvokeCommandAction Command="{Binding GridViewSelectionChanged}" CommandParameter="{Binding SelectedItem, ElementName=LoadingGridView}" />//需要对应的Commadn  和需要传的参
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                    <telerik:RadGridView.Columns>
                                        <custom:MyColumn Header="#"
                                 Width="30"
                                 CellStyle="{StaticResource style1}" />
                                        <telerik:GridViewSelectColumn Name="select"   TextAlignment="Center" Width="35"  Header="多选" EditTriggers="None">
                                        </telerik:GridViewSelectColumn>
                                        <telerik:GridViewDataColumn  DataMemberBinding="{Binding TPSFPkey}" IsFilterable="True"  TextAlignment="Center"  Header="TPSFPkey"/>   
                                        <telerik:GridViewDataColumn  DataMemberBinding="{Binding MLO}" TextAlignment="Center"  Header="MLO" IsFilterable="True"></telerik:GridViewDataColumn>
                                        <telerik:GridViewDataColumn  DataMemberBinding="{Binding Pkey}" IsVisible="False"  TextAlignment="Center"  Header="Pkey" IsFilterable="True"></telerik:GridViewDataColumn>
                                        <telerik:GridViewDataColumn  DataMemberBinding="{Binding LoadingCargoPkey}" IsVisible="False"  TextAlignment="Center"  Header="LoadingCargoPkey" IsFilterable="True"></telerik:GridViewDataColumn>
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding UserPkeyCreator}" Header="UserPkeyCreator" IsFilterable="True" ></telerik:GridViewDataColumn>
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding UserPkeyModifier}" Header=" UserPkeyModifier" IsFilterable="True" />
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding DateTimeCreated,Mode=OneTime}" Header="DateTimeCreated" IsFilterable="True" />
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding DateTimeModified,Mode=OneTime}" Header="DateTimeModified" IsFilterable="True" />
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding AuditStat}" Header="AuditStat" IsFilterable="True" />
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding TPSFLoadingPkey}" Header="TPSFLoadingPkey" IsFilterable="True" />
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding CntrNum}" Header="CntrNum" IsFilterable="True" />
                                    </telerik:RadGridView.Columns>
                                </telerik:RadGridView>
                                <telerik:RadDataPager PageSize="20"
                                  FontSize="12" Margin="0,-1,0,0"
                                  Source="{Binding Items, ElementName=LoadingGridView}"
                                  IsTotalItemCountFixed="True"
                                  DisplayMode="FirstLastPreviousNextNumeric, Text"/>
                                <StackPanel Name="stack1" Visibility="Collapsed"  Orientation="Horizontal">
对于RadGridView外部的按钮控件,想拿到RadGridView的选中项的值,我们可以用CommandParameter来传值,SelectedItems, 可以拿到RadGridView
被选中的多项;
                                    <Button Content="删除" Command="{Binding DataContext.DeleteSelect,
                                   RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}"
                            CommandParameter="{Binding SelectedItems, ElementName=LoadingGridView}" Grid.Row="2"  Width="75"/>
                                    <Button Content="退出"  Grid.Row="2"  Width="75" Click="Button_Click" />
                                </StackPanel>

你可能感兴趣的:(command)