开发者

Add EventToCommand to each Row in xaml

Is there a way to add a DoubleClickEvent to each Row in xaml rather than using the event of the datagridcontrol?

Something like this (this code does not work):

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


Use a template instead of a style. (This assumes that the xceed datagrid's DataRow is templatable.)

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜