Parameter命令绑定中没有CommandParameter

Parameter命令绑定中没有CommandParameter

本文介绍了ListParameter命令绑定中没有CommandParameter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有成功从ListView项目发送CommandParameter.我的代码在下面.

I am not succeeding in sending CommandParameter from ListView item. My code is below.

<ListView x:Name="myList" ItemsSource="{Binding MyData}"
     <ListView.View>
          <GridView>
               <GridViewColumn>
                    <GridViewColumn.CellTemplate>
                          <DataTemplate>
                                <Button Command="{Binding Path=DataContext.MyCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" CommandParameter="{Binding SelectedItem, ElementName=myList}" >
                                      <Button.Content>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="{Binding Path=SomeValue}" />
                                            </StackPanel>
                                      </Button.Content>
                                 </Button>
                           </DataTemplate>
                      </GridViewColumn.CellTemplate>
               </GridViewColumn>
          </GridView>
     </ListView.View>
</ListView>

单击ListView上的项目时,该命令称为okay,但CommandParameter显示Nothing.这是什么问题?

When the item on ListView is clicked, the command is called okay, but the CommandParameter shows Nothing.What's the problem here?

ViewModel命令在这里:

ViewModel command is here:

Public ReadOnly Property MyData As List(Of myObject)
    Get
        Return _myObjectrepo.GetAll()
    End Get
End Property

Public Property MyCommand As ICommand
    Get
        If _myCommand Is Nothing Then
            _myCommand = New RelayCommandWithParameter(Of myObject)(AddressOf Navigate)
        End If
        Return _myCommand
    End Get
    Set(value As ICommand)
        _myCommand = value
    End Set
End Property
Private _myCommand As ICommand

...以及尝试使用CommandParameter的过程

...and the procedure where I try to use the CommandParameter

Private Sub Navigate(m As myObject)
    If m IsNot Nothing Then

    End If
End Sub

...但是上面的过程中m无效.

...but the m is Nothing in the above procedure.

推荐答案

从评论中复制了答案:

CommandParameter="{Binding}"

这篇关于ListParameter命令绑定中没有CommandParameter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 07:38