简体   繁体   English

DataGridListView's SelectedItem null 在MVVM中绑定后 WPF C#

[英]DataGridListView's SelectedItem null in MVVM after binding WPF C#

i'm having some troubles with databinding of selecteditem of a datagridlistview.我在数据网格列表视图的选定项的数据绑定方面遇到了一些麻烦。 I implemented an event on doubleclick with a command and commandparameter.我使用命令和命令参数在双击上实现了一个事件。 I'd like to pass as command parameter the row that i double clicked (the selected item).我想将我双击的行(所选项目)作为命令参数传递。

I tried this:我试过这个:

   <ui:DataGridListView Grid.Row="1" Margin="6" MinHeight="200"
                         Name="PTest"                          
                         ItemsSource="{Binding Source={StaticResource model}, Path=EsecuzioniCollection}"
                         VisibleItems="{Binding Source={StaticResource model}, Path=VisibleItems, Mode=OneWayToSource}">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="MouseDoubleClick">
                <i:InvokeCommandAction CommandParameter="{Binding Source={StaticResource model}, Path= SelectedItem}" Command="{Binding Source={StaticResource model}, Path=MouseDoubleClickCommand}">
                </i:InvokeCommandAction>
            </i:EventTrigger>
        </i:Interaction.Triggers>
        ...............
</ui:DataGridListView>

But when command is invoked the parameter SelectedItem is null:但是当调用命令时,参数 SelectedItem 是 null:

 public async void MouseDoubleClick(PerimetriTestDataItem item)
    {
        ...
    }

I tried also putting SelectedItem={Binding SelectedItem} on ui:DataGridListView but it's null on my viewmodel.我也尝试将 SelectedItem={Binding SelectedItem} 放在 ui:DataGridListView 上,但它在我的视图模型上是 null。

Is there a way to bind the row?有没有办法绑定行? any tricks?任何技巧?

Thank you谢谢

Without any other information, I am assuming that SelectedItem is a property inside model , it does not look like SelectedItem in the StaticResource model is bound to anything.在没有任何其他信息的情况下,我假设 SelectedItem 是model中的一个属性,它看起来不像 StaticResource model 中的 SelectedItem 绑定到任何东西。 I believe you can try one of two steps.我相信您可以尝试以下两个步骤之一。

  1. Replace i:InvokeCommandAction CommandParameter="{Binding Source={StaticResource model}, Path= SelectedItem}" Command="{Binding Source={StaticResource model}, Path=MouseDoubleClickCommand}"> with i:InvokeCommandAction CommandParameter="{Binding Source={ElementName=PTest, Path=SelectedItem}, Path= SelectedItem}" Command="{Binding Source={StaticResource model}, Path=MouseDoubleClickCommand}">i:InvokeCommandAction CommandParameter="{Binding Source={StaticResource model}, Path= SelectedItem}" Command="{Binding Source={StaticResource model}, Path=MouseDoubleClickCommand}"> i:InvokeCommandAction CommandParameter="{Binding Source={ElementName=PTest, Path=SelectedItem}, Path= SelectedItem}" Command="{Binding Source={StaticResource model}, Path=MouseDoubleClickCommand}">

  2. Instead of SelectedItem={Binding SelectedItem} on ui:DataGridListView try SelectedItem={Binding Source={StaticResource model}, Path=SelectedItem}而不是 SelectedItem={Binding SelectedItem} on ui:DataGridListView 试试SelectedItem={Binding Source={StaticResource model}, Path=SelectedItem}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM