RoutedCommands
-
Hi, this may seem like a stupid question, but I've looked everywhere and I couldn't find anything that could help me. I'm developing a WPF project and in it I have two user controls, at the moment the first has only one button and the second is pretty much a canvas with a custom border. Both of them have been added to the main window in their respective locations. What I want is, when I click the button in the first user control another control is added to the my second user control (canvas). Since I'm a bit desparate and confused about all this, I would just settle for a simple message box to show, with the code being written in the canvas code behind. Everywhere I looked said that routed commands where the best option, but I cant seem to make them work. I should also say that I can make the routed commands work only inside the first user control. Both user controls are in the same project, but have different namespaces. I'd appreciate any help and I appologise if my question seems unclear. Thanks
-
Hi, this may seem like a stupid question, but I've looked everywhere and I couldn't find anything that could help me. I'm developing a WPF project and in it I have two user controls, at the moment the first has only one button and the second is pretty much a canvas with a custom border. Both of them have been added to the main window in their respective locations. What I want is, when I click the button in the first user control another control is added to the my second user control (canvas). Since I'm a bit desparate and confused about all this, I would just settle for a simple message box to show, with the code being written in the canvas code behind. Everywhere I looked said that routed commands where the best option, but I cant seem to make them work. I should also say that I can make the routed commands work only inside the first user control. Both user controls are in the same project, but have different namespaces. I'd appreciate any help and I appologise if my question seems unclear. Thanks
Well, generally WPF code is made data driven. So from the Usercontrol use DataContext to pass a Dataobject on the User Control. Make the adjustment so that the user control loads something whenever the data object is modified. We use this by implementing the data class from
INotifyPropertyChanged
. INotifyPropertyChanged[^] Other than that you can also keep a property/dependency property to help load the object from outside.Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
Visit My Website-->**