I have about 20 pages in my Silverlight nav app. I have 1 usercontrol that I want to use across all 20 pages. I a开发者_Go百科lso need the state of the usercontrol to look the same across the 20 pages. So for example if they are on page 1 of the app and they change the background color of the usercontrol it will be the same color across the other 19 pages. Any ideas on how to implement something like this?
If those pages are all alive at the same time, then you'll need to have 20 instances of your user control. Just because one control can be present only once in a tree.
Otherwise, you could store reference to your control somewhere in the globally accessible place (e.g. App class, ServiceLocator pattern, whatnot) and add it to your pages when appropriate.
Or even better, you can have only one ViewModel class, which will represent user control state (e.g. Brush property), and set it as a DataCOntext for all instances of your UserControl.
Hope this helps.
精彩评论