I’m just beginning to work with WPF’s databinding, so please excuse the basic nature of this question.
I have a user control which is receiving a custom event and one of the event arguments is an object that I want to bind to the controls in this user control.
I have some examples of binding to a control like a combobox and then setting a datacontext on the grid to the selected item of the combobox and then binding the controls to it. I’m interested in doing something similar in this user control, but I don’t know what to bind the object to that comes over with the event.
Any suggestions are welcome.
Thank you.
If your event handler is in the code-behind of the UserControl, you can just write something like:
And then in your XAML you can just write normal bindings and they will bind to the properties of the object (e.g. if the object has property “Foo” you would write “{Binding Foo}” in the XAML). If you don’t want to bind the entire user control to the object, but rather just one element in your XAML, you would just set the DataContext of that one element. For example, if you had:
you would write:
And then in the XAML you could say things like:
Where your event args object had a “GridWidth” property.