I'm a newbie in GUI development, especially with WPF, and do not know related patterns, so I ask you about a problem I want to wake up from time to time and I am not sure about the best solution.
Our three user controls include A, B, C and Control A control B, Control B control. Control is a button on C. The click event for this app will have to deal with using data from class A. I look at the following possible ways to resolve this situation:
1) Add Method InnerButtonClick (Object Sender, Routing, and E.E.E. E) in Class A. Our button will be confronted with bubbling incidence due to minus:
i) This method will catch all the buttons. Click with kids from A So I have to apply some conditional argument in the method to check that the event is due to our button.
ii) The properties of C are not easy to go there. It may seem like
var btn = (button) e.OriginalSource; String Username = ((ActionButton) (User Control) ((StackPanel) BTN. Parent).) Username; If the button is in User Control C in StackPlanel and StackPanel.
2) Provide access to the necessary data for Class C. For example, pass data in class B, and then c. Minas:
i) It is often not so easy.
ii) This causes additional methods / constructor parameters.
3) Make a static method in class A, which can be said by class C methods. Minuses:
i) It seems a little unpleasant. The method of singleton, pattern of 'dark side of force').
Root Commands Set the command on the button in C for this type of scenario, and command A Add binding, there is no need to know about A, and C does not have to know anything about A. When the button is clicked in C, the command bubble will bubble before commandbinding, which will be in your case.
EDIT:
You can use the commandpayer's property Text from the text box If you need to get more information than 1 field, you can handle button click events in C You can collect the required data in an object, and then in the form of a parameter, you can trigger the command from that object.
Comments
Post a Comment