Page Options
You are here : Blog
...and the Geek shall inherit the Earth Blog... Minimize
Author: Lance Larsen Created: 11/4/2008 1:10 PM
...and the Geek shall inherit the Earth...

I’m on the airplane flight back to Wisconsin from the Microsoft MIX 10 conference in Las Vegas.  Working on some Windows Phone 7 demo applications and wanted blog an illustrated guide to adding the ApplicationBar to your new Windows Phone apps.

image

1) Start by downloading the new Windows Phone 7 Series demo tools at https://developer.windowsphone.com/ – as follows:

Once on that page, click on the “Download the Tools Today!” button, then click on Download the Developer Tools!

You’ll download the “vm_web.exe” which when you run it proceeds to download and install an ~238MB file.  Installation for went very smoothly, and installed everything I needed to start developing my applications.  Thumbs up to the Mobile Team – this was extremely well done – sure this wasn’t easy to get working that well.

Note, there is a link on the previous page for downloading Demo Code – grab those examples – specifically the “Application Bar Sample” which is what I dissected to write this article.

2) Open up Visual Studio, then go to File –> New –> Project – there you will see “Silverlight for Windows Phone” under the “Installed Templates”. 

In this case we’re building a “Windows Phone Application” so select that, name your project and click “OK”.

image3) In your “public MainPage()” method start by adding the following code:

   1: //----------------------------------------------------------------------
   2: // Create the application bar
   3: //----------------------------------------------------------------------
   4: ApplicationBar = new ApplicationBar();
   5: ApplicationBar.IsMenuEnabled = true;
   6: ApplicationBar.Visible = true;
   7: ApplicationBar.Opacity = 1.0;

4) VS will alert you that you are missing the “Microsoft.Phone.Shell” reference.  So right click on References and “Add a Reference” and find the “Microsoft.Phone.Shell” as illustrated – that should clear up that issue.

So in the code above, we see that we’re creating a new ApplicationBar instance, and setting a couple properties so it’s visible and so we have the “...” icon on the right (see more on that later below).

image

5) Next open the “Application Bar Sample” Demo Code and copy the images folder from that project into yours.  You should see three images in the image folder as you can see in the Solution Explorer illustration.

6) Now that we have the ApplicationBar instance and the graphics included in our project – we want to put icons on the ApplicationBar.

Add the following code – which created the ApplicationBarIconButton objects and associates the graphics.

   1: //----------------------------------------------------------------------
   2: // Create the application bar icons
   3: //----------------------------------------------------------------------
   4: ApplicationBarIconButton hide = 
   5:    new ApplicationBarIconButton(new Uri("/Images/expand.png", UriKind.Relative));
   6: ApplicationBarIconButton opacity = 
   7:    new ApplicationBarIconButton(new Uri("/Images/opacity.png", UriKind.Relative));
   8: ApplicationBarIconButton enabled = 
   9:    new ApplicationBarIconButton(new Uri("/Images/menuenabled.png", UriKind.Relative));

image 7) We follow up with adding the following code to wire up the event that do something when the buttons on the ApplicationBar are clicked. 

Note, that you don’t have these event methods defined yet – for me, I have ReSharper installed and it gives me an easy way to create stub methods by just clicking on “Create method ‘enabled_Click' ”

   1: //----------------------------------------------------------------------
   2: // Wire up the events
   3: //----------------------------------------------------------------------
   4: hide.Click += hide_Click;
   5: opacity.Click += opacity_Click;
   6: enabled.Click += enabled_Click;

Either way – here is an example of the code called when the event handler fires, just setup similar methods for the other events.

   1: private void enabled_Click(object sender, EventArgs e)
   2: {
   3:     throw new NotImplementedException();
   4: }

8) Now we just easily add the ApplicationBarIconButtons to the ApplicationBar as follows:

   1: //----------------------------------------------------------------------
   2: // Add icons to the menu bar
   3: //----------------------------------------------------------------------
   4: ApplicationBar.Buttons.Add(hide);
   5: ApplicationBar.Buttons.Add(opacity);
   6: ApplicationBar.Buttons.Add(enabled);

9) Just a little more code gives us the ability to have the great functionality of the “More Options” scrolling up section native to the ApplicationBar.  We follow the same patter as above, creating the instance this time of ApplicationBarMenuItems, wiring up their click events and adding them to the ApplicationBar.MenuItems collection, as follows:

   1: //----------------------------------------------------------------------
   2: // Creat the menu items
   3: //----------------------------------------------------------------------
   4: ApplicationBarMenuItem foregroundItem = new ApplicationBarMenuItem("use foreground color");
   5: ApplicationBarMenuItem accentItem = new ApplicationBarMenuItem("use accent color");
   6:  
   7: //----------------------------------------------------------------------
   8: // Wire up the events
   9: //----------------------------------------------------------------------
  10: foregroundItem.Click += foregroundItem_Click;
  11: accentItem.Click += accentItem_Click;
  12:  
  13: //----------------------------------------------------------------------
  14: // Add the menu items to the application bar
  15: //----------------------------------------------------------------------
  16: ApplicationBar.MenuItems.Add(foregroundItem);
  17: ApplicationBar.MenuItems.Add(accentItem);

image10) You’re almost there – run the application in the simulator and you get the illustration to the left.

Wait?  What happened to our nice icons?  Why are there “X”s?

This stumped me for a little bit – and is one reason I wanted to share my experience with everyone.

 

 

 

 

 

 

image 11) Ok – so missed one step after adding the images to the project.  Click on one of the images in the Solutions Explorer – you see that that “Build Action” is set to “Resource” – simply change all of them to “Content”.

 

 

 

 

 

 

image

image

12) Run your application again in the emulator – and awesome!  There are our icons – and – when we click on the “...” we see the ApplicationBar scroll up to reveal our ApplicationBarMenuItems.  Very very cool rewards for a minimal amount of code.

 

Summary: Wow. Even cooler than having written this article while on the airplane ( gotta love the free WiFi trial on AirTran ) – I’m loving the new Windows Phone 7 Series (WP7) development tools.

“I’m all in” ( see what terminology one picks up in Vegas ) for WP7 development and will continue to evangelize the product! 

Way to go Microsoft Mobile Team – looking forward to getting great apps out into the Marketplace. – and hopefully sooner than later replacing my iPhone with a brand new sparkly Windows Phone. :)

Good coding!

image

Currently at Microsoft MIX 2010 conference in Las Vegas (#Mix10) in the session on “Distributing and Monetizing Windows Phone Applications and Games”.

Very excited about the huge potential for leveraging my existing .NET skills and my extensive background with Mobile Development.  Highly encourage others to download the development tools – very smooth installation process – encourage others to get the tools.

Also, while sitting in the conference, I already registered for an account to distribute Window Phone 7 applications – the Marketplace is going to be huge!

To register – go to http://developer.windowsphone.com – the price is just $99.

I’m just waiting for… “Your corporate approver … will soon receive an email with instructions on how to authorize your request. Please ensure the corporate approver follows these instructions to finalize your registration.” – so if you’re my “corporate approver” reading this – drop me an email. :)

“According to a recent survey from Microsoft, remote-working programs can benefit employees and employers alike through increased productivity, reduced overhead and happier workers.  …they are actually more productive and efficient when working remotely. With less time spent commuting and fewer cubicle “drive bys” causing distractions, respondents say, more time can be spent on the task in front of them.”

Read More...

I’m a big fan of EF (Entity Framework), specifically loving EF4 in Visual Studio 2010 RC – and wanted to share some tips that I’ve learned working with EF1/EF4 along the way.

In EF, you generally either do LINQ to Entities, or LINQ to ObjectQuery – both have their advantages and disadvantages. 

Specifically advantages that I use are for LINQ to Entites is that you can use lamda expression formatting for strong typed retrieval – not so for LINQ to ObjectQuery (see below). 

But LINQ to ObjectQuery has it’s advantages as well – the one big advantage that I take advantage of in my coding patterns is the fact that I can call the .Include() method after the initial query – thus I can “Eager” load tables based on some condition.  Will show more on late .Include() calls in future blog posts.

I believe that this is non-obvious, and I’ve never seen anyone else doing this before – but works very well for the approach I take, and wanted to share in case you need to use LINQ to ObjectQuery and distain not being able to use strong typed query formatting < as I do > in LINQ to Entities.  :)

   1: //----------------------------------------------------------------------
   2: // Example LINQ to ObjectQuery - note not using strong type where clause
   3: //----------------------------------------------------------------------
   4: ObjectQuery<RepositoryFile> selectQuery1 = 
   5:     this.DataContext.RepositoryFiles.Where("item.FileName = 'Word.doc'");
   6:  
   7: //----------------------------------------------------------------------
   8: // Example of LINQ to Entities - note we DO strong type the where clause
   9: //----------------------------------------------------------------------
  10: IQueryable<RepositoryFile> selectQuery2 = 
  11:     this.DataContext.RepositoryFiles.Where(item => item.FileName == "Word.doc");
  12:  
  13: //----------------------------------------------------------------------
  14: // Example of LINQ to ObjectQuery but using LINQ to Entities strong 
  15: //  typed syntax, but then casting it back to ObjectQuery
  16: //----------------------------------------------------------------------
  17: ObjectQuery<RepositoryFile> selectQuery3 = 
  18:     (ObjectQuery<RepositoryFile>) this.DataContext.RepositoryFiles
  19:     .Where(item => item.FileName == "Word.doc");

image

355MB/s of goodness are on on their way…

So, in an effort to boost my development laptops overall speed (it’s not bad but it’s not an i7 <g>) – I decided address my drive speed bottleneck and to look at picking up an SSD (Solid State Drive).

Started doing my research, and found that most the reviews were from 2009.  So in an effort to get the latest and greatest, searched for CES 2010 and SSD and came up with awesome reviews for the Crucial RealSSD C300.

But alas, it was not out (been checking their site daily-ish) – until today!

So, now it has been ordered, should be here by the end of the week… :)  Will review it when I get it.

image_thumb2As president of the Madison .NET User Group (MADdotNET) I’m very pleased to bring Chad Albrecht in to present on “Succeeding With Agile & TFS 2010” for our March 3rd presentation meeting – I’m a big fan of the Agile development process, and combining those with all the great new features in TFS 2010 – this should be awesome! 

Twitter: http://twitter.com/chadalbrecht
Blog: http://blog.chadalbrecht.com

Have you ever found yourself getting latest from a team project, and someone else “accidentally” checked in code that doesn’t compile?  Well – none of us are perfect – but – sure we all find this quite annoying. 

So imagemy first instinct is to right click on the file in “Solution Explorer” and back out the file to a previous version – but the file is buried deep in the file hierarchy.

So, instead of hovering over the file name tab in the main window, then following that path in Solution Explorer – found the following option in Visual Studio.

Go to Tools –> Options –> Projects and Solutions and click the “Track Active Item in Solution Explorer”.

Nice…  Try it out.

30e4aeb5-f7cd-4db2-857f-0385dcf366c3 I’ve seen several presentations on XAML before, and my take away perception from the brief overviews was that XAML was an excellent markup language for visual layouts to be used in both WPF and Silverlight applications. 

True or False? 

Well, it’s Both – while it IS a great way to layout controls – but it’s really a whole lot more.

What I truly didn’t realize was that XAML is essentially a Serialization of the code – thus you can do almost everything you can do in code – directly in XAML.  And that’s a powerful and non-obvious revelation.

Karl Shifflett and Jamie Rodriguez had a fantastic 2-Day training session… Highly encourage others to take any opportunity to see these guys.

In fact my brain hurts from information overload…! :)

Here are some useful WPF Links brought up during training:

Demo Code & Slide Deck – lots and lots of fantastic code and information – will need to dive deeper.

XAML Power Toys – VERY COOL! Tools to quickly put XAML code together.

WPF Example: Cipher Text – Not only a good example of WPF, but a useful application for securing information – thinking of switching to using it.

WPF Example: Southridge Realty – Wow, really amazing MVVM application for demo Realty company.

WPF Example: Collapsible ListBox – Great example showing the power or XAML with no additional code behind.

WPF Binding Cheat Sheet – There’s no intellisense for bindings – so this helps.

image If you’re not getting enough geek-to-geek face time at our MADdotNET meetings – there’s another software dev group in Madison – not specifically .NET – check out: http://softwaredev.meetup.com/113/

Print  
Categories Minimize
Search Blog Minimize
Publish Dates Minimize

Copyright 2008 by Lance Larsen ( A.I. Labs )
Privacy StatementTerms Of Use