WPF ComboBox Mvvm 绑定

WPF ComboBox Mvvm binding

我正在尝试从列表中获取选定的值到命令中。有没有简单的方法将命令参数绑定到所选项目?

<ComboBox HorizontalAlignment="Left" Margin="-56,10,0,0" VerticalAlignment="Top" Width="120" SelectedIndex="0" ItemsSource="{Binding Time}">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Loaded">
                <i:InvokeCommandAction Command="{Binding TestCommand}" CommandParameter="{Binding }"></i:InvokeCommandAction>
            </i:EventTrigger>
            <i:EventTrigger EventName="SelectionChanged">
                <i:InvokeCommandAction Command="{Binding TestCommand}" CommandParameter="{Binding }"></i:InvokeCommandAction>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </ComboBox>

当我尝试

                <i:EventTrigger EventName="SelectionChanged">
                <i:InvokeCommandAction Command="{Binding TestCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}},Path=SelectionBoxItem}"></i:InvokeCommandAction>
            </i:EventTrigger>

奇怪卡住了​​为什么?

<ComboBox x:Name="Combo" HorizontalAlignment="Left" Margin="-56,10,0,0" VerticalAlignment="Top" Width="120" SelectedIndex="0" ItemsSource="{Binding Time}">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Loaded">
                <i:InvokeCommandAction Command="{Binding TestCommand}" CommandParameter="{Binding ElementName=Combo, Path=SelectedItem}"></i:InvokeCommandAction>
            </i:EventTrigger>
            <i:EventTrigger EventName="SelectionChanged">
                <i:InvokeCommandAction Command="{Binding TestCommand}" CommandParameter="{Binding }"></i:InvokeCommandAction>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </ComboBox>

如果您为组合框命名,您可以使用 ElementName 绑定并绑定到路径 SelectedItem