C# 列表框选择索引作为命令参数

C# 列表框选择索引作为命令参数,c#,wpf,mvvm,C#,Wpf,Mvvm,如何将命令参数绑定到列表框中的选定索引?我的代码: <ListBox> <i:Interaction.Triggers> <i:EventTrigger EventName="MouseDoubleClick"> <i:InvokeCommandAction Command="{

如何将命令参数绑定到列表框中的选定索引?我的代码:

<ListBox>
        <i:Interaction.Triggers>
            <i:EventTrigger
                EventName="MouseDoubleClick">
                <i:InvokeCommandAction
                    Command="{
                              Binding Path=SelectPath,  
                              Mode=OneTime, 
                              RelativeSource={
                                            RelativeSource Mode=FindAncestor, 
                                            AncestorType={x:Type UserControl}
                                     }
                 }" 
                    CommandParameter="ListBox.SelectedIndex" // how can this parameter be bind to SelectedIndex
                    />
            </i:EventTrigger>
        </i:Interaction.Triggers>

    </ListBox>
编辑:

我所做的和它的工作:创建了新的dp属性SelectedListBoxIndex,将其与SelectedIndex绑定,然后将该属性作为命令参数传递。但是有没有更好的方法呢

        <ListBox
        SelectedIndex="{
                    Binding Path=SelectedListBoxIndex,
                    RelativeSource={
                                    RelativeSource Mode=FindAncestor, 
                                    AncestorType={x:Type UserControl}
                                   }}">

        <i:Interaction.Triggers>
            <i:EventTrigger
                EventName="MouseDoubleClick">
                <i:InvokeCommandAction
                    Command="{
                              Binding Path=SelectPath,  
                              Mode=OneTime, 
                              RelativeSource={
                                            RelativeSource Mode=FindAncestor, 
                                            AncestorType={x:Type UserControl}
                                     }
                 }"
                    CommandParameter="{
                    Binding Path=SelectedListBoxIndex,
                    RelativeSource={
                                    RelativeSource Mode=FindAncestor, 
                                    AncestorType={x:Type UserControl}
                                   }
                 }" />
            </i:EventTrigger>
        </i:Interaction.Triggers>

    </ListBox>

一种方法是设置ListBox x:Name,然后将CommandParameter绑定到其SelectedIndex属性,如下所示:


一种方法是设置ListBox x:Name,然后将CommandParameter绑定到其SelectedIndex属性,如下所示:


@我知道这个答案是正确的,用答案左边的按钮接受它。@我知道这个答案是正确的,用答案左边的按钮接受它。