Page Options
You are here : Blog
...and the Geek shall inherit the Earth Blog... Minimize
Author: Lance Larsen Created: 11/4/2008 3:58 PM
Microsoft .NET Development

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_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.

image 

Now, when architecting this solution, have to take many factors into consideration:

1) First and foremost, time is of the essence ( literally ) – as many of the organs have as small as a 6 HOUR window of opportunity from surgical “procurement” to transplantation.

2) The UWHealth ITS ( Info Technology Systems ) team generally consists of non-.NET developers who are tasked to maintain and customize purchased products developed from a wide variety of other companies.

This project is a new type of endeavor for the department as a whole – ie. in house ASP.NET development.

So while the development staff and project management team are top notch and extremely knowledgeable about the what the application will need to do – they are relatively new to developing critical ASP.NET core applications.

And most importantly in my decisions, they will need to be able to maintain the developed ASP.NET application once the application is past the development stages.

So…

1) For now, choose to go with an n-tiered implementation (obviously ) -- and based on the experience level of the folks that are going to support it after I depart, going with classic WebForms, not MVC.  

As to MVC, I'm not necessarily sold on the benefits of MVC over WebForms myself yet either – spent time playing with the MVC RC1 from Microsoft that allows for easy setup of MVC – and that works great!, but aside from making TDD a little easier - not sure moving away from WebForms will happen any time soon for most projects.

2) Right now looking at how I want to implement my DAL, looking at Linq to Entity as I haven't used that before and it appears to be the direction Microsoft is going, as opposed to Linq to SQL, etc.


Just started a new gig Monday before last – hired on as an independent contractor for a Senior .NET Architect position at UWHealth here in Madison, WI for a 6 to 12 month project. 

Tasked to build an OPO ( Organ Procurement Organization ) application that we’ve named DonorLink. 

DonorLink will be used anytime someone who is an “Organ Donor” ( ie. someone who has the “red dot” on their driver’s license ) passes away in the hospital.  Then DonorLink becomes a pivotal asset in the coordination of managing the process of getting the “procured” organs – everything from a heart, lungs, eyes, kidney, tissues of all sorts, etc – from the donor to a recipient who is waiting on an organ transplant to prolong their life.  Can’t get much more important than that.

Very pleased that they reached out to bring my experience and expertise to Architect their ASP.NET application as well as potentially mobile and other application in the future.

Will keep blogging on the Architecture process – and looking for feedback from my .NET peers.

imageWent down to the MDC (Microsoft Development Conference) in Chicago,  Came down early to meet up with some of our Microsoft contacts.  Great opportunity to network - and line up speakers of the Madison .NET User Group (www.maddotnet.com).

Asked by Larry Clarkin (who did a great job of running the speakers, etc.) to assist with the Community track, so we put some time aside to speak about the .NET User Group as well as the other technologies that were being discussed throughout the day.

imageSpent time investigating Azure (www.azure.com) - Microsoft's cloud computing implementation.  This is Microsoft's way to compete with Amazon, etc with virtual server "Cloud" application hosting -- but they're taking a spin on it by leveraging the existing .NET developer's skill base and tightly integrating it into their development tools.  Azure is currently in CTP (Community Technical Preview) - look forward to spending more time on this and identifying when and where it would benefit my clients.

Also, very excited after looking at the upcoming release of Visual Studio 2010.  Some of the features that look to be exceptional are the QA features - giving the developer not only a VIDEO of any exceptions as they occur on the tester's machine, but also give the developers the ability to debug into the very code - and hit the exact exception - to see why the error occurred.  No more wasting time chasing down errors that are difficult to reproduce...

Also VS2010 has some nice Regression / Unit testing enhancements - including the concept of a "Gated Checkin" - wherein the team can set it up that prior to any code check-in, all code is updated, and built to validate that there will no longer be any broken builds.

Finished up with getting the low down on the latest ASP.NET 4.0 features that are in planning to be rolled out.  Check out -- www.codeplex.com/aspnet -- for more details on those.

Thanks to all the folks at Microsoft, very nice one-day event.

CardSwipe I do a lot of development for mobile devices. 

Specifically, I needed to integrate a mag-stripe reader that fits into the CF slot of a PocketPC into a SmartDevice C# compact framework application that I am in the process of creating. 

The overall goal is to allow a credit card ( but could be any card with a mag-strip ) to be swiped directly on the mobile device and have that data integrated into the application.

Took advantage of the SerialPort class in .NET, and spun off an example application illustrating that to share with anyone else needing similar architecture.

Download: The "CardSwipe" example code ( Visual Studio 2008 )

Read More »

Print  
Categories Minimize
Search Blog Minimize
Publish Dates Minimize

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