代码之家  ›  专栏  ›  技术社区  ›  CodeWeasel

将EventToCommand添加到xaml中的每一行

  •  0
  • CodeWeasel  · 技术社区  · 15 年前

    类似这样的内容(此代码不起作用):

        <UserControl
            xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
            xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
            xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" >
        <xcdg:UserControl.Resources>
                <Style TargetType="xcdg:DataRow">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseDoubleClick">
                            <cmd:EventToCommand Command="{Binding SelectCommand, Mode=Default}" CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataGridControl}}}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Style>
        </xcdg:UserControl.Resources>
    ...
    
    1 回复  |  直到 15 年前
        1
  •  1
  •   Matt Casto    15 年前

    使用模板而不是样式。(这假设xceed datagrid的DataRow是可模板化的。)

    <UserControl ...>
        <UserControl.Resources>
            <ResourceDictionary>
                <DataTemplate x:Key="DataTemplateKey">
                    <Grid>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseDoubleClick">
                                <cmd:EventToCommand Command="{Binding SelectCommand}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                        <!-- put your row template here -->
                    </Grid>
                    <CheckBox Content="{Binding Path=ApplianceActionID, Converter={StaticResource LookupConverter}, ConverterParameter=ApplianceActionLookupValues}"
                              IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" />
                </DataTemplate>
    
            </ResourceDictionary>
        </UserControl.Resources>
    
        <!-- UI -->
    
    </UserControl>