Event in one UserControl changes text in another
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!
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!
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: Event in one UserControl changes text in another
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.
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
Thanks for the reply. This is what I was looking for; something high level.
Who is online
Users browsing this forum: Baidu [Spider] and 11 guests