Cannot bind command within a ListBox

前端 未结 1 1725
孤独总比滥情好
孤独总比滥情好 2021-01-28 12:22

My WPF uses the MVVM approach. I\'m trying to bind 2 controls within my list control



        
相关标签:
1条回答
  • 2021-01-28 13:17

    The ancestor search finds the control, not the DataContext, so you'll need to tell your binding where to find the DeleteCommand property. If your ViewModel is the DataContext of the MainWindow then you can just use:

    <Button Content="Delete me now" 
        Command="{Binding RelativeSource={RelativeSource 
                      Mode=FindAncestor, AncestorLevel=1, AncestorType=Window}, 
                      Path=DataContext.DeleteCommand}" 
        CommandParameter="{Binding FilePath}" />
    
    0 讨论(0)
提交回复
热议问题