Saturday, May 25, 2019 ..:: Home ::.. Register  Login

Peter Henry on Facebook  Peter Henry on LinkedIn  Peter Henry on Twitter

All blog entries are the opinions of the author and do not necessarily reflect the opinions of their employer. All the code presented is for explanation and demonstration purposes only. Any damages incurred to your site and/or data are not the responsibility of the author. Every effort is taken to ensure the code properly compiles, however sometimes there are some hiccups and you might be required to do your own debugging.
   TechTidBits (Blog)  

WP7 Application names and DRY just don't mix, why is that?

Sep 6

Written by:
Monday, September 06, 2010 11:21 PM  RssIcon

Static resource as application nameEver notice who WP7 apps ALWAYS repeat the hard coded application name and page name string?  Ever wonder why?  Ever wonder how you can FIX it?  Read on for a quick'n'easy way to keep things DRY!

Static resource as application nameDo you hate repeating yourself?  I said, do you HATE repeating.......oh you get the idea! LOL 

But seriously, when you code, do you use cut'n'paste when you REALLY should be refactoring methods?  Do you try to keep things DRY?  If you do, and you're learning WP7 dev (which is why I hope you're reading my blog LOL) you probably noticed you're forever repeating the page name and application name on every new page/form.  I'm HOPING something in your brain was/is twitching everytime you add a new page and you see the same'ol strings over and over again (like below with the new WP7 page templates).

New page defaults

Well, my brain was always twitching when I did it, but I'm still learning WP7, XAML, SL3 and MANY other MS TLA (Three Letter Acronyms) and well, I just had too many other things to learn first.  UNTIL this week when I read a blog from Kevin Wolf titled, Windows Phone 7 - Quick Tip.  Ok, so the title's not really indicative of the contents, but I read it, and thought it was brilliant (and I fully expect MS to implement this in an upcoming respin of the tools to be honest!).

The crux of this TIP is two fold, add a string resource to the App.XAML file like such (note, you'll probably need to add the namespace up top too, at least I had to with the current rev of the WP7 tools, could change in the future?).

App.XAML snippet

Next, just use it!

Using static resource on page

That's it!  You're all set.  Need to add a new page?  At least now you can cut'n'paste the ApplicationTitle static resource Text value.  Now, if you're with a company who changes product names like the Sens going up'n'down the standings, then this will save your bacon!  Change it ONCE in the app.xaml file and BINGO, all changed throughout the WP7 app.

Now that you know how to put your WP7 Application Name in one place and share it around, it's time to go grab a coffee and get coding!


PS  That logo up there on the WP7 app, is from an old knitted Montreal Canadiens jersey (1909-1910).  Yes, I am a Habs fan!  If you're new to my blog, WELCOME!   And you'll see a bit of a theme, pot shots at the Sens (like above), the Leafs (cause it's sooooooooo easy) and lots of Canadiens logos PLASTERED all over my demos.  They're demos, they're meant for fun, I hope you take it all in the spirit it was created.  If you're offended by any of this....uuhhhh.........hhhhhmmmm you better not read some of my Java posts! :> LOLOLOLOLOLOL!!!!! AAAAHHHHHAAAAAAA!!!!!!!!!!


Source Code:

The Wolf Bytes: Windows Phone 7 - Quick Tip by Kevin D. Wolf

Wikipedia: Don't repeat yourself

Location: Blogs Parent Separator TechTidBits

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Add Comment   Cancel 
Copyright 1999-2012 by   Terms Of Use  Privacy Statement