Page 1 of 1

Event in one UserControl changes text in another

Posted: 15 Apr 2015, 20:37
by walhore
Hi Guys,

I have two usercontrols. When I roll over a button in usercontrol A, I want the text in a textblock in usercontrol B to change. Could you recommend a good approach for Noesis? I actually have several buttons inside several usercontrols and would need the textblock (or textblocks) to change in the main usercontrol each time a user rolls over one of the buttons. I'm not sure how to access elements/properties that are in separate usercontrols.

Thanks!

Re: Event in one UserControl changes text in another

Posted: 17 Apr 2015, 21:09
by sfernandez
It all depends on the layout and structure of your application.

For example if UserControl B knows about the existence of UserControl A, then it can just ask him about the desired named buttons (because a UserControl maintains its own NameScope where content subtree elements are registered) and hook to their MouseEnter/MouseLeave events to update the corresponding text.

Another approach a bit more complex can be to use a ViewModel attached to both UserControls, and communicate the changes via the ViewModel: UserControl A updates a property for each Button that is hovered, ViewModel updates a string property, and UserControl B reads that string property to update the TextBlock.Text property.

If you need assistance with an specific step I can help you with the code/xaml.

Re: Event in one UserControl changes text in another

Posted: 21 Apr 2015, 23:28
by walhore
Thanks for the reply. This is what I was looking for; something high level.