views:

38

answers:

0

Ive been staring at my code too long and need a kick in the right direction please.

In my poker chip calculator I have multiple pages (currently only "Chip Calculator" is visible on that link). Each page has a menu at the top (the one on the top left below the nav tabs) which has actions local to that page (e.g. Load/Save chipset on the Calculator page) and then about 40% of actions on the menu are shared on all pages - e.g. About PTM (under Help), Hide Menu, Go Fullscreen etc.). The same applies to the Right-click context menu - it has shared global and local actions.

So now I am about to do the next page and it seems as though I need to copy the whole Menu control and the context menu which means a lot of duplicated code/event handlers/.xaml for the common functionality.

I need some ideas on how to best refactor this so I can just have the common code in one place and add the local stuff on each page to the menu/context menu.

Here's my thoughts so far:

1) I can't put the main menu on MainPage.xaml as each page needs to have page specific .xaml (I would prefer to do it declatively rather than programatically as it is fairly complex)

2) If I did put it on MainPage.xaml then each local page would have to write it's portion of the menu programatically?

3) I therefore have to put a new menu object on every page. (unless there is a better way!?)

4) Likewise - I currently have the Context popup menu on the MainMenu.xaml page but the event handlers have to be on the local page for the local actions.

5) So I was thinking I could maybe put all the common stuff into their own .xaml pages (even if it is just a menuitem like "Resize to Fullscreen") and then use XamlReader.Load to load it programatically (or maybe I can declare it as a local resource) on the page? The problem with this is that you can't declare event handlers in the .xaml, so you have to wire them up on the page anyway (http://forums.silverlight.net/forums/p/45743/124100.aspx).

6) Maybe a combination - I put the main menu and context menu once on MainPage.xaml, and then on each local page it reads .xaml and programatically injects it into placeholders in the menu.

So... I need some ideas please - at the moment the most maintainable seems to be to copy and paste the menu and the popup menu on to every page and handle all the global events locally (I can abstract the functionality into "helper" classes so that the local pages are just calling the global methods).