Binding a WPF Button CommandParameter to the Button itself in DataTemplate

后端 未结 2 1455
感动是毒
感动是毒 2021-01-02 01:39

I have a DataTemplate that represents AppBar buttons that I declare through a collection of custom AppBarCommand objects.

  public AppBarCommand(RelayCommand         


        
相关标签:
2条回答
  • 2021-01-02 01:51
    <Button Command="{Binding Command}" 
            CommandParameter="{Binding RelativeSource={RelativeSource Self}}" />
    

    Your Command property should be the generic version of the RelayCommand: RelayCommand<object> for instance.

    0 讨论(0)
  • 2021-01-02 01:59

    Answer like Miklós Balogh said, or you can:

    <Button x:Name="MyButton" Command="{Binding Command}" CommandParameter={Binding ElementName=MyButton ... /> 
    
    0 讨论(0)
提交回复
热议问题