Add parameter to Button click event

前端 未结 4 966
抹茶落季
抹茶落季 2020-11-29 04:17

I have a wpf button like this:


<         


        
4条回答
  •  日久生厌
    2020-11-29 05:02

    Simple solution:

    In your handler, cast the sender object to Button and access the Tag property:

    var myValue = ((Button)sender).Tag;
    

    A more elegant solution would be to use the Command pattern of WPF: Create a Command for the functionality you want the button to perform, bind the Command to the Button's Command property and bind the CommandParameter to your value.

提交回复
热议问题