I am creating Buttons dynamically in my code, is there a way I can store a custom object in my button so I can use it when I press this button ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Consider using the command pattern and bind a command to the button’s
Commandproperty and use theCommandParameterProperty to store your object.When the button is clicked the
Executemethod of your command will be invoked using theCommandParameter(containing your object) as parameter.It would be good to know the scenario you are working at. Generating XAML by code is a sign you may be on the wrong track as long as you are not building custom controls.
Most things can be accomplished via data bindings and repeater controls such as listboxes, menus, datagrids, etc. Are you familar with the MVVM pattern?