walhore
Topic Author
Posts: 19
Joined: 25 Feb 2013, 17:24

Event in one UserControl changes text in another

15 Apr 2015, 20:37

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!
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Event in one UserControl changes text in another

17 Apr 2015, 21:09

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.
 
walhore
Topic Author
Posts: 19
Joined: 25 Feb 2013, 17:24

Re: Event in one UserControl changes text in another

21 Apr 2015, 23:28

Thanks for the reply. This is what I was looking for; something high level.

Who is online

Users browsing this forum: Bing [Bot] and 2 guests