0

有没有办法将 DoubleClickEvent 添加到 xaml 中的每一行,而不是使用 datagridcontrol 的事件?

像这样的东西(此代码不起作用):

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

1 回答 1

1

使用模板而不是样式。(这假设 xceed 数据网格的 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>
于 2010-06-25T16:48:26.860 回答