Installing the WPF Bits

OK, looking back I’m thinking my instructions last week for getting to the WPF bits installed were a tad confusing, so I’m going to give it one more shot.

Step 1 – Install .Net 3.0.

If you’re already on Vista, skip this step. If you are on XP, you can download .Net 3.0 from: http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&displaylang=en . Make sure your XP has been patched with Service Pack 2.

Step 2 – Have a copy of Visual Studio.

If you have Visual Studio already, skip this step. If not, you can grab an express edition version at http://msdn2.microsoft.com/en-us/express/default.aspx . You’ll want to select Windows Development, and pick either C# or VB.Net.

Step 3 – The Windows Software Development Kit

The Windows SDK has lots of cool tools, what you are interested in is one called XAMLPad. You can find the SDK at: http://www.microsoft.com/downloads/details.aspx?FamilyId=C2B1E300-F358-4523-B479-F53D234CDCCF&displaylang=en . Even though it says Vista, the SDK will also install on XP with SP2, or Windows Server 2003.

Step 4 – Visual Studio extensions for WCF & WPF

Finally, you’ll want to install the Visual Studio extensions, these will allow you to create new projects for both the WCF and WPF. There are two prerequisites to installing the extensions. First, make sure you have the SDK (from Step 3) installed first. There are some bits in there the extensions need.

Second, all of the help for the extensions is local, so make sure you go into Visual Studio and set the help to “Local, then On-line”, other wise the installer will complain. OK, with those to prerequesites handled you’re ready to proceed.

Below is the website to download the extensions. Even though the title reads CTP, these are the latest (and final) bits you’ll see for this, Microsoft is putting all it’s efforts into Visual Studio 2008. You can get the extensions at http://www.microsoft.com/downloads/details.aspx?familyid=f54f5537-cc86-4bf5-ae44-f5a1e805680d&displaylang=en

Step 5 – Reboot

I generally find it a good idea to do a reboot after installing new bits, especially ones from Microsoft. After the reboot it might also be a good idea to run a Windows Update, just in case there are any security bits that need installing / updating.

Bonus Step – If you have an MSDN subscription, you should also download and install the Expression Blend tool, it will make your job of generating XAML much easier.

New version of CodeRush/RefactorPro

Just thought I’d take a short break from WPF to make you aware there has been a new release to that wonderful Visual Studio add-in CodeRush. The product has now broken the 100 refactorings mark!

You can read the announcement from DevExpress at http://www.devexpress.com/Home/Announces/CodeRush25.xml

If you are not familiar with DevExpress’ CodeRush/RefactorPro tools, you can read my original post at https://arcanecode.wordpress.com/2007/01/09/visual-studio-add-ins-coderush/

The new version already works with Visual Studio 2008. Talk about being on the ball, VS2008 is still in Beta and they’ve already got refactorings out there just for it!

The Brains of WPF

In yesterday’s demo, I gave instructions to add references to WindowsBase, PresentationCore, and PresentationFoundation. Today I thought we’d take a few minutes to talk about what these are and what they do.

Together these three DLLs make up the heart of Windows Presentation Foundation. WindowsBase defines most of the base types needed by WPF, and should always be included. PresentationCore builds on WindowsBase by providing the base types for most of the GUI components you’ll use. PresentationFoundation is the big animal on the block, he holds all of the WPF controls.

Now that you know the DLLs, let’s talk briefly about the namespaces you’ll encounter. System.Windows contains two core types, Application and Window. These are the two you’ll use as a platform to build your user interfaces on, and you’ll see them often.

The other one you saw yesterday was System.Windows.Controls. In here are all of the standard controls you might expect: button, label, textbox, checkbox, etc. Yesterday when you saw the XAML <Label> block, WPF renders that from the System.Windows.Controls namespace. By the way, you need to note that XAML, like C#, is case sensitive. So <Label> will work, but <label> and <LABEL> will not.

Over time there are some other children of System.Windows we’ll be seeing, such as Shapes (which, as you might guess holds standard shapes like rectangles and circles), Media (used for 3D and more), Document (for creating XPS files), and Markup which can be used to parse XAML.

We’ll dive deeper into all of these as time goes by, but I wanted to give you a brief introduction so you’d understand what bits belonged where in the WPF world, and why you need to include those references and using/import statements in your code.

WPF and XAML

XAML is the definition language most often used to define a WPF based user interface. Using XAML you can define sleek, modern and highly functional applications.

Most people talk about XAML and WPF interchangeably, but I feel I need to kick off our discussion with an important concept:

XAML != WPF

XAML and WPF are, in fact two separate things even if they are closely linked. XAML is a definition language, similar to HTML. Well, more like HTML, WINForms and XML collided together in a Mythbusters type of explosion, and XAML is the result.

XAML requires a framework to execute. Often that framework is WPF, but it’s not necessarily so. Internet Explorer can interpet and display a XAML page, as can tools like XamlPad. Take this simple example:

<Page xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221; xmlns:sys=”clr-namespace:System;assembly=mscorlib” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221; >
<Grid>
<Label>Welcome to ArcaneCode!</Label>
</Grid>
</Page>

Here you can see XamlPad displays the label in the upper part of the window:

clip_image002

No WPF, no compilation, no other magic, just the XAML Parser at work. You could save the code snippet above, and open it in Internet Explorer if you so wished.

Now let’s create another user interface, this time we’ll use WPF and NO XAML! Start a new project in Visual Studio, and pick BlankProject (note, do NOT pick Windows Project (WPF). We’ll use it later, but not today.)

Add references to three assemblies in the .Net tab: PresentationCore, PresentationFramework, and WindowsBase.

Now add a class, I named mine wpftest. Here’s my code:

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows;

using System.Windows.Controls;

 

namespace wpf001

{

  class wpftest : Application

  {

    [STAThread]

    static void Main()

    {

      wpftest mytest = new wpftest();

      mytest.Startup += MyTestStartup;

      mytest.Run();

    }

 

    static void MyTestStartup(object sender, StartupEventArgs e)

    {

      arcaneWindow aw = new arcaneWindow();

      aw.Show();

    }

  }

}

Note the use of an arcaneWindow class, let’s create that now:

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows;

using System.Windows.Controls;

 

namespace wpf001

{

  class arcaneWindow : Window

  {

    Label lblWelcome = new Label();

 

    public arcaneWindow()

    {

      this.Title = “Greetings!”;

      this.Width = 320;

      this.Height = 120;

 

      lblWelcome.Content = “Welcome to ArcaneCode!”;

      this.AddChild(lblWelcome);

    }

  }

}

Note the following things:

First, I’ve added two “using” lines, System.Windows and System.Windows.Controls. Next, I needed to create a new window (arcaneWindow) and inherit from the base Window type. Finally, I created a WPF label control, and added it to our window via AddChild.

Once you get all of it in, run the program and you should see:

clip_image003

There you go, you’ve just created a WPF user interface without a single line of XAML.

My point of this kick off was to demonstrate the difference between WPF and XAML. Most times, you will probably be using WPF and XAML in conjunction, but you don’t HAVE to.

In the coming days, we’ll delve a little deeper, and I’ll explain more of what some of the code you’ve seen today means.

WPF Resources

Yesterday I pointed out where to download all the bits you need to get into WPF. Today I thought I’d share some good resources on learning WPF.

First off is Todd Miranda’s site Xperimentality http://www.nxtdimension.com/blog/ . Todd is an MVP and has done many of the videos that appear on the Windows Client site.

Speaking of the WindowsClient.Net site, you can find many of those videos at http://windowsclient.net/learn/videos.aspx , just scroll down to the WPF area.

Todd Miranda’s videos on the Expression suite can be found on the Expression Knowledge Center site, http://www.microsoft.com/Expression/kc/resources.aspx?product=web&type=video . There are also videos by others.

Channel 9 has now reached 100 items on WPF: http://channel9.msdn.com/tags/WPF

Mark Miller recently did a DNRTV episode on Custom Controls in WPF, find it at http://www.dnrtv.com/default.aspx?showNum=72 . Also on DNRTV, Brian Noyes did a two parter on WPF, found here http://www.dnrtv.com/default.aspx?showNum=56 and here http://www.dnrtv.com/default.aspx?showNum=59 .

Another great blog is Lester’s WPF Blog, http://blogs.msdn.com/llobo/default.aspx . Lots of good stuff from the author of XAMLPadX, which I recommended yesterday.

Finally, a book recommendation, I’m finding Adam Nathan’s book on WPF to be a really good read. It’s more than technical enough to keep an experienced reading, and all of the code samples are in color! http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917/ref=pd_bbs_sr_1/103-4574773-3941455?ie=UTF8&s=books&qid=1187125352&sr=8-1

Taking the WPF Plunge

I wrote earlier that I felt WPF and XAML were the UI design platform of the future ( https://arcanecode.wordpress.com/2007/08/03/the-ui-of-the-future/ ). I’ve decided to put my time where my (some would say big) mouth is, and devote some time to learning WPF. In case you want to come along for the ride, lets look at what you need to get started.

First, you need the .Net Framework 3.0. Odds are you already have it, if you have Vista you definitely have it. If you are still on XP, and haven’t downloaded it grab your copy from http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&displaylang=en . Make sure your XP has been patched with Service Pack 2.

That’s it, that’s all you have to have. However there are some things that will make your life easier. Visual Studio 2005, for example. Odds are if you read this blog you already have a version, but if not grab one from http://msdn2.microsoft.com/en-us/express/default.aspx . You’ll want to select Windows Development, and pick either C# or VB.Net.

Finally, you’ll want the Windows Software Development Kit. The Windows SDK contains a very useful tool called XamlPad, which you can use to quickly test your XAML code. The Vista version is at http://www.microsoft.com/downloads/details.aspx?FamilyId=C2B1E300-F358-4523-B479-F53D234CDCCF&displaylang=en . UPDATE (Aug 15): I should have been a little more awake when I wrote this. Even though the download has Vista in the title, the SDK will actually install and run on Windows XP (with SP2) and Server 2003 in addition to Vista.

If you’re on XP, or want something other than the SDK check out XamlPadX at http://blogs.msdn.com/llobo/archive/2007/04/23/update-xamlpadx-v2-1.aspx .

Finally, if you are lucky enough to have an MSDN Subscription, take a look at Expression Blend and Expression Web, I’ll be looking at them later.

There, that ought to keep you busy for a bit!

UPDATE UPDATE (Aug 16th)Well I did it again. When I posted the Aug 15th update (at the bottom) I grabbed the wrong text and pasted it in. Obviously, the Workflow Foundation extensions don’t do you any good when you want to work with WPF. Instead I meant to refer you to the extensions for WPF & WCF at http://www.microsoft.com/downloads/details.aspx?familyid=f54f5537-cc86-4bf5-ae44-f5a1e805680d&displaylang=en . Don’t let the fact that it reads CTP shake you, this is the last release for VS2005, Microsoft decided to make all further updates to the VS2008 product. The bits work fine though, and add templates so you can create WPF/WCF projects.

One note, when you go to install this extension, it will first recommend you have the Windows SDK (see link earlier in this message) installed. Second, it will recommend you set your help in Visual Studio 2005  to use local instead of on-line as the primary source. Just be aware of these two quirks.

I’ll leave the Workflow link below active though, it won’t hurt to install it, and you might want to dive into WF at some point.

UPDATE (Aug 15th): One more item you’ll want if you intend to use Visual Studio, you’ll want the Extensions for Windows Workflow Foundation, which you’ll find here http://www.microsoft.com/downloads/details.aspx?familyid=5D61409E-1FA3-48CF-8023-E8F38E709BA6&displaylang=en . (It’s only a 6 mb download, so it shouldn’t take long.)

Arcane Searching

I think we’d all agree the internet is one of the greatest productivity tools around, allowing us to find vast stores of information. I’m sure you’ve also heard it’s the greatest time waster, with lots of distracting sites or useless pages that get in the way of the results we want.

I find it really valuable to have a good search tool, one that focuses on the content I need, and limits the scope of the search to relevant areas. Of course we’ve all heard of Google, the 500 pound gorilla of search engines. While the do a pretty decent job, when your search phrase returns half a million hits it can be difficult to narrow down.

Recently I’ve found the Microsoft engine, Windows Live ( http://www.live.com/ ), has gotten a lot better, especially when looking for .Net related developer content.

My favorite so far though, is Search.Net ( http://searchdotnet.com/ ), a site put together by coding legend Dan Appleman. Dan ( http://www.desaware.com/ ) created a Google powered site, but maintains the list of sites it searches so you know that you are only combing sites devoted to programming and not Happy Harry’s House of Wild Women.

Another site I just learned about this week is Koders ( http://www.koders.com/ ). It’s a site devoted to searching through source code. It also has some helps that will let you zoom in on what you want. You can pick the language, or specify your search word needs to be in the class name, method name, or interface name. This kind of search is valuable when you are looking for an example, or trying to avoid reinventing the wheel.

A similar site is Krugle ( http://www.krugle.com/ ). It has similar paradigm to Koders, allowing you to search through code.

The final code search tool I’ll mention is Google’s new Code Search engine ( http://www.google.com/codesearch?hl=en ). It allows you to search using regular expression syntax, which is a nice feature (I just wish regular expressions weren’t such a pain in the underwear to use).

I have to give a quick thanks, most of these I learned about through either my listening of Dot Net Rocks ( http://www.dotnetrocks.com/ ) and HanselMinutes ( http://www.hanselminutes.com/ ) or through Scott Hanselman’s new forum site, which I blogged about yesterday.

Those are the list of place I go when I need to find something, how about you?

Arcane Links

Some miscellaneous topics to cover for today. First, I had the need to copy several thousand files from one machine to another, about 6 gigs worth. Explorer? No thanks, to slow and unreliable. Fortunately I had recalled reading a post on Scott Hanselman’s blog just the other day on this topic. http://www.hanselman.com/blog/XCopyConsideredHarmfulRobocopyOrXXCopyOrSyncBack.aspx

Since the machine I was using to do the copying was Vista, I used RoboCopy. Worked like a champ. The bad part was I didn’t even know I already had this tool until I’d read Scott’s post. Always nice when you go hunting for a tool only to discover you’ve already got it and it’s ready to go.


On the subject of SOA, Redmond Magazine released an article on Microsoft’s SOA strategy. http://redmondmag.com/features/article.asp?editorialsid=756

It was a long article and interesting, although it seemed to have an anti-Microsoft tone. I picked up a subtle, and perhaps condescending, knocking of Microsoft for not falling into lockstep with other industry players like IBM. While I do agree Microsoft sometimes comes a little late to the party, I don’t think it has to jump on the party boat to be an effective player in the industry.


Windows Communication Foundation Guru Jeff Barnes is planning on some new WCF posts in the near future, so be sure to keep an eye on his site if you play in the WCF realm. http://jeffbarnes.net/portal/blogs/jeff_barnes/archive/2007/08/08/coming-soon-wcf-3-5-posting-blitz.aspx

Jeff’s also working on a WCF Site (http://jeffbarnes.net/portal/blogs/jeff_barnes/archive/2007/08/06/planning-a-wcf-community-site.aspx), another good reason to keep an eye on his blog.


Finally, Scott Hanselman has opened up a forum area on his site, some good info and discussions can be found here. http://www.hanselman.com/forum/

Happy Programmers

According to the Secret Society of Happiness (http://www.sohp.com/) today, August 8th is National Happiness Day. It got me to wondering, as a developer or IT professional, what makes you happy?

For me it can be the little things. When I added a third monitor to my setup at work, I was happy.

When I get “that” problematic section of code working, I’m happy.

When I learn about a new .Net class and learn it’s in’s and outs, I’m happy.

When I get to learn some new tech, such as SOA (Service Oriented Architecture), I’m happy.

When I get to hang out with other geeks and get into really arcane conversations about the nuances of some technology, I’m happy.

When I’m driving down the road, with no accidents to block my way, listening to a new podcast, I’m happy.

Most of all though, is when I meet with a user to find his needs, then in a few hours can come up with a solution for him. To hear the user say “wow, I spent hours gathering that data every week, now I can get it in a matter of minutes. You’ve saved me hours of work.” That makes me happy.

What makes you happy?

As a side note, I also have to wonder, if it’s a “secret” society, why do they have a website?

Announcing the SOA Society

I’m pleased to announce the formation of Alabama’s newest user group, the SOA Society. The group will focus on Service Oriented Architecture, and educate its members on all aspects of SOA including design, implementation, development, maintenance.

In addition the group will cover the business side of SOA. We seek to educate enterprise leaders on topics like return on investment, creating business cases for implementing SOA, and encouraging a culture of designing systems from the outside in.

Our audience will be broad, we want to appeal to everyone from developers to IT managers to business owners, evangelizing the benefits of SOA as not only an internal productivity tool but a sales tool for interacting with your customers.

We plan to hold our first member drive at Birmingham Alabama’s TechBirmingham (http://www.techbirmingham.com/) TechMixer in October 2007. Monthly meetings will then begin the same month, in the Birmingham area.

But you don’t have to wait! If you would like to get involved with the formation of the new group, or simply want to be added to the e-mail list shoot me an e-mail at arcanecode at gmail dot com. This is a community based group, and we welcome the involvement of the community!

Just Code It

Jeff Atwood has an interesting post on his Coding Horror site entitled “Yes, But What Have You *Done*?” ( http://www.codinghorror.com/blog/archives/000809.html ). Programmers, Jeff says tend to be natural introverts, and left to their natural devices will migrate toward head down coding.

“But it is possible to go too far in the other direction, too. It’s much rarer, because it bucks the natural introversion of most software developers, but it does happen. Take me, for example. Sometimes I worry that I spend more time talking about programming than actually programming.”

I know how Jeff feels. In my role as a development lead I spend a lot of time in meetings, or talking to other developers about their projects. As a result I wind up spending a lot of time late at night doing coding, just to keep up with the latest and greatest techniques.

The need for code experience directly resulted in one of my “How To Be A Better Developer…” ( https://arcanecode.wordpress.com/2007/07/13/being-a-better-developer-in-6-months/ ) pledges.

I will work all the code samples in the book. Reading is one thing, but doing is even better. Personally, I find I get a better understanding when I actually type in the code samples and run them. And not just run what’s in the book, but tweak it, experiment with it.

I’m amazed at the number of times I meet some guy who comes across as a self proclaimed expert on a subject. When I quiz the person or try to ask tough questions, it turns out said individual read a book, but never actually wrote any code. Book learning is great, I certainly buy enough books every year to know, but there’s no substitute for doing.

When learning something new, start with the samples. Work it, tweak it, understand it. Then, if appropriate use it on your project at work. If it’s not appropriate, find someone else’s project that it would be a good fit for. Offer to work a few hours unpaid overtime and contribute some code to their project. They’d probably be grateful for the help, and might repay with some pointers and critiques.

Can’t find an appropriate project at work? There are thousands of open source projects out there, find one where you could contribute. Or look around the community; find a charity that needs some programming done.

It’s easier than you think to find some real world places to apply your coding skills. So what are you waiting for, just code it!

Happy Birthday

Hard as it is to believe, today, August 5th 2007, marks one year since I started the blog. I admit the first few months were a bit slow when it came to posts, but it’s really taken off since late October of 2006.

The biggest surprise to me is how much I’ve enjoyed blogging. Everyday I try to learn something new. Being able to take what I’ve learned and talk about it on the blog only reinforces my understanding and, I hope, adds some value to you the reader.

I do admit that I tend to be all over the place with my content. I guess it’s a reflection of both my interests and what I have to deal with on a daily basis. As a development team lead, I lend a helping hand to everyone’s projects. So on any given day I’m jumping back and forth between ASP.Net, WinForms, Windows Services, Web Services, AJAX, C#, VB, Java, SQL Server Data Warehousing tools (SSIS, Reporting Services), and Oracle, to name a few.

I think though that even if work didn’t require the broad range it did, I’d probably still be working in all of it. I find it all fascinating, AJAX, WPF, WCF, Linux, Virtualization, SOA, there just doesn’t seem to be enough hours in the day to keep track of it all. There’s so much cool technology out there I feel like the proverbial kid in a candy store.

Let me close by saying thanks. Thanks to all of you who visited, sent e-mails, and posted comments. It’s been a great year and I look forward to many more.

Robert / Arcane Code

Design From The Outside In – Establishing a New SOA Focused User Group

For those in the Birmingham, Alabama area, some colleagues and I are in the process of establishing a new user group. This group will focus on Service Oriented Architecture – SOA. While we plan to cover all aspects, from the top level design down to the nitty gritty details, our main focus will be in the architecture area.

If you have an interest in SOA, experience with it, are passionate about it, or just want to learn more we’d love to get your feedback. We hope to finalize a group name, establish meeting locations and dates, and begin getting programs lined up in the very near future.

For more info just e-mail me, arcanecode at gmail dot com.

The UI of the Future

At yesterdays IPSA meeting (http://ipsaonline.org) our local MVP Todd Miranda (http://www.nxtdimension.com/blog/) gave a great presentation on XAML. My coworker Bin and I both felt it was an hour of our time well invested. I don’t know of many other ways we could have learned as much with the same investment of our time.

Coincidentally just yesterday I was in the book store and picked up a book on AJAX (Introduction AJAX for ASP.Net by Dino Esposito). Not too long ago we rolled out the AJAX for ASP.Net libraries on all of our ASP.Net servers, and I’ve wanted to dig into it.

It got me to thinking about user interfaces and the technology we used to create them. Not too long ago it was all text based. Just recently we showed a young collegue and old DOS based application still in use. Her reaction was “Did people actually used to use that?”

Windows made it better, with a standard set of controls that we could easily drop onto our forms. As Todd pointed out in his presentation today though, any attempt to change the basic appearance of these items could take thousands of lines of code.

With the introduction of XAML, I firmly believe we are on the verge of a new revolution in user interface design. It seems to have been a bit slow to start, but all it will take is that one “killer app” done in XAML to rock the boat. The recent introduction of Silverlight (formerly WPF/E) and it’s use of XAML will only serve to increase it’s popularity.

So where will we be in 10 years? I think under the covers compilers will be generating a lot of AJAX code, but I’m not so sure that we’ll be coding a lot of Javascript to deal with it. I feel a lot will be handled for you.

Of the two, right now I’d say XAML will be the more predominant player. I think the code generation tools will improve, but I feel a good, basic understanding of what’s going on with XAML will be crucial to every developer.