By BillKrat
Source code available at http://SolrContrib.CodePlex.com change set 94057
Below I create a horizontal button toolbar from a collection of the SolrContrib MenuModel objects. Naturally I'll want to style these to look better but within an Agile mentality I am simply looking for functionality at this point. Each module that is loaded stores a reference to its Presenter in this collection (as well as its MenuTitle) on the application controller. The style that generates this button toolbar will be shared with both the Desktop and Silverlight versions of this Multi Targeted application.
Figure 1
One of the things I love about Prism, and Dependency Injection (DI), is my ability to easily/quickly get a reference to system resources. Below I'm able to get a reference to the system's application controller (which holds a method to retrieve menu items) with two lines of code as shown on line 8 and 9.
In figure 3 you'll find that the collection used to populate our MenuModels (line 15 on image below) holds a MenuTitle property as well as other valuable information such as a reference to the Module, Region and Presenter (in the base). We'll bind our buttons content to the MenuTitle of this collection.
Figure 2
Figure 3.
Note below that I'm able to reference a static resource without any resource declarations. As with all of the modules in this application you won't find any source code in the code-behind but there is a wee bit of magic going on in the baseclass; with a base declaration I'm able to easily swap out the UserControl with my baseclass ViewBase (which derives from UserControl). Note: I did have to update the code-behind to remove the reference to UserControl so the compiler would not complain.
Figure 4.
This minor update to my view will automagically expose a series of resource dictionaries contained in the Gwn.Resources.xxxx library where xxxx=Desktop or Silverlight as applicable.
There are "shared" resources, such as the MenuItems resource shown on line 10 in the above image, as well as platform specific resources.
Figure 5.
For the "platform" specific resources I am able to declare styles that are not compatible on both Desktop and Silverlight platforms. For example, Silverlight does not have a DockPanel but the Toolkit does so I'm able to create an ItemsControlDocked style specific to Silverlight (the Desktop looks similar to the following but simply references the built-in DockPanel control.
The MenuItems style shown on line 5 (bottom right pane in image below) is shared between both the Desktop and Silverlight applications. It is not shared in the sense of linked files (which won't work with resources because the linked file does not exist on the hard drive); I am Reusing Data Templates by sharing the very same ResourceDictionary file - this saves me time by not having to copy/paste resources that can be easily shared between Desktop and Silverlight as is the case with MenuItems below:
Figure 6.
No comments:
Post a Comment