Databound menu item names in XAML

I keep telling the engineers who work with me that once we ship, we’ll have to write some articles with all the tips and tricks that we’ve discovered in Microsoft’s .NET Framework v.3, specifically WPF and WCF. The technology is easy enough to use, as I’ve written before, that even a product manager can do it.

My engineers challenged me to find a way to dynamically bind the name of our application into the menus, so that we would not have to update the menu names separately when we changed the code name of the product to the final released name. After some playing around, it turns out to be pretty trivial. As in my About Box example, you have to reference the AssemblyInfo class, which has the name of the assembly as a property that can be databound. Then it’s just a question of databinding the name to the menu.

With the way that menus are created by default in Expression Blend, this can look tricky because the text that is shown is in a parameter of the MenuItem tag called Header. What you have to remember is that WPF allows you to embed other controls into various contexts, but that you generally have to be explicit about how you’re doing it. So your code might have started out looking like this:

<MenuItem Header="_Help">
  <MenuItem Header="_About MyProgramName"/>
  <MenuItem Header="MyProgramName Help"/>
</MenuItem>

After you break out the header element and embed the databound names, it ends up looking like this:

<MenuItem Header="_Help">
  <MenuItem>
    <MenuItem.Header>
       <TextBlock>
          <TextBlock Text="About " />
          <TextBlock Text="{Binding Path=Info.Title, Mode=Default, Source={StaticResource ApplicationBaseDS}}" />
       </TextBlock>
    </MenuItem.Header>
  </MenuItem>
  <MenuItem>
     <MenuItem.Header>
        <TextBlock>
           <TextBlock Text="{Binding Path=Info.Title, Mode=Default, Source={StaticResource ApplicationBaseDS}}" />
           <TextBlock Text=" Help" />
        </TextBlock>
     </MenuItem.Header>
  </MenuItem>
</MenuItem>

It’s probably obvious enough to an experienced WPF programmer, but I found no ready references for making this happen so I figured I’d give it back to Google.

End in sight to reboot hell?

I have been struggling with Windows Vista for a month or two. Regularly the system ran out of resources, regularly reboots were required to re-enable functionality. The symptoms were eerily reminiscent of classic GDI resource heap exhaustion: windows would refuse to open, pop-up menus stubbornly stayed closed, applications reported an inability to save to disk or access the registry.

I am now trying various patches to see if I can fix the problem. After a blue screen of death (yes, those still happen on Vista), it occurred to me that the problem must be in a device driver; after all, that code gets to play at a privileged OS level where it can do things like attempt to overwrite read-only memory. I suspected the video driver, and attempted to use an update from Intel’s web site to update the driver (for the record, it’s the Intel Mobile Chipset 945), but was told that the upgrade was not installable on my machine (an HP Compaq NC6320 laptop).

Now I am getting a message from the Windows problem reporting system that one of my issues may be fixed by a hotfix for KB 931671. We’ll see if this does fix the problem, or if I continue down the path of no return with this OS. Already not a good sign: I am being forwarded for the second time in a 20 minute call to another department because the reps I have been speaking to are not authorized to distribute the hotfix.

Vista: Very, very hungry

I run Windows Vista at the office. Generally I get along with it just fine, and our company’s software plays pretty happily with it. But every now and then in my daily work I hit some kind of wall. Sometimes it manifests as a problem with Microsoft Outlook: when I try to launch Word to read an attachment, it starts up the Office Installer instead, then complains that it is suffering from “Windows Installer error 1450” and can’t proceed. Cancelling or clicking OK brings me to the same place: a copy of Word that complains that it hasn’t been installed for the current Windows user.

Other times, the problem manifests as a refusal to open other software applications, even Notepad, or to open new explorer windows. When I hit this point, even clicking on the funky little restart menu to try to get to the restart menu option won’t open the submenu. I have to hold the power key down to force the power to cycle.

It feels for all the world like the bad old days of Windows 3.1 or Windows 95 when one of the system resource heaps would be exhausted. But that shouldn’t be happening in Vista, or any post-NT OS, for that matter.

What’s weird is that applications that are already open, e.g. Firefox, appear to run just fine as long as you keep them running.

I can’t find anything on Microsoft.com or on the web at large about the issue, so I’m posting something to jog my own memory the next time I run into the problem.

Product managers writing code, and other scary things

When your product manager checks code into your source control project, it means one of three things:

  1. Your engineering team is short-handed.
  2. Your project is really in trouble.
  3. Your development environment is really, really easy to use.

While I’m not sure that #2 isn’t true, I found #3 to be absolutely true working on a recent software release with my team. We’re using the Windows Presentation Foundation, aka Avalon, and I used Microsoft’s Expression Blend to make the project’s About window.

WPF is designed to enforce separation of code and presentation, and tools like Expression Blend enable that. The presentation markup enabled me to automatically include the current assembly information (version number, product name, copyright string), plus free memory information, and even a little animation.

The trick was in learning how to do data binding. I specified various modules of the .NET Framework as data sources, then bound text objects to methods in the framework. Interestingly, the easiest way to get assembly information was in the Microsoft.VisualBasic.ApplicationServices namespace, in a class called AssemblyInfo; of course it doesn’t matter since the same code can be accessed by any .NET compatible language, including C#. The only challenge came in showing the available memory, since the methods in Microsoft.VisualBasic.Devices.ComputerInfo return memory in bytes. I wanted to show the information in megabytes, so I attached some simple C# code as a converter to represent the information in megabytes and format it appropriately for the user’s region.

Like I said: simple.

Holy crap: an honest to goodness Easter egg

Thanks to Macintouch, I just spent a virtual eternity (okay, five minutes, but these days that feels like an eternity) playing Asteroids. The original Asteroids. Tucked away inside Microsoft Office 2004.

Word was a while back that Microsoft had put a moratorium on Easter eggs. I wonder how the team slipped this one in. I wonder whether Rick Schaut would have anything to say on the topic, if we asked him nicely.

Thought for the day: Platform lock-in, good and bad

A review of a new PowerShell book on Slashdot features a great comment from an anonymous coward who gives the best argument against supporting multiple platforms that I’ve ever read:

I hate re-using code because it forces me to solve new problems every day. I’d rather create new value on Mondays only, and then spend the rest of the week re-doing the same work on my other platforms. It gives my mind a chance to rest, and I can drink heavily mid-week and still be able to do my job.

I sure hope they charge extra for it, make it a resource hog, lock out third-party extensions, and then discontinue it as soon as I’m dependent on it. I really liked the 1980s and look forward to reliving them.

The nice thing about the comment is that it contains the pro and con of supporting multiple system architectures back to back, and both perspectives are funny, and true.

Webex Outlook Addin and Outlook 2007

If, like me, you live and die by Webex, you might have been as frustrated as I was to find that the Outlook add-in for Webex (which allows you to schedule online meetings right from your Outlook calendar) doesn’t install on Outlook 2007. I was quite surprised to find this, actually, since I had happily been running it on my old computer. But I realized I had actually migrated it—I had originally installed it against Outlook 2003, and it had happily continued to work when I upgraded to Outlook 2007.

So I hacked my way into making it work. Basically all you have to do is start from a working installation of the add-in (downloadable from your Webex account page), then copy the binary files from the Webex program files directory to the machine with Outlook 2007, register the DLLs, then add a registry entry that registers the add-in. On my machine, the registry entry for the last step looks like this:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USERSoftwareMicrosoftOfficeOutlookAddinsOutlookAddin.Addin]
"FriendlyName"="ADOutlook2K Addin"
"Description"="ATLCOM Outlook Addin"
"LoadBehavior"=dword:00000003
"CommandLineSafe"=dword:00000000

Note that installing this WILL NOT work unless the DLLs from the add-in have properly been registered.

Once I did the above steps, I simply recorded my sign-in information and was able to start scheduling meetings again. Yee haw.

Update: Apparently WebEx has fixed this issue, though it doesn’t explain why I had to hack and post about it before anyone told us that it was an issue, much less that they had fixed it. Sigh.

Zune Phone to suck just as hard as the Zune…

As someone who is counting the days until his current Cingular contract expires in June so that he can pick up an iPhone, I thought the rumor that Microsoft was planning a Zune branded phone was pretty funny. Because, of course, the Zune brand has shown such market power to date that it has completely destroyed the iPod’s hold on the market.

Oh, wait. It hasn’t? Um, never mind.

But the take of the Crazy Apple Rumors Site on this rumor is one of the funnier things I’ve read in a while:

Beyond just the name, however, sources indicate that the Zellular Phone Call will have certain limitations inherited from the Zune platform.

For example, all calls will be wrapped in Microsoft’s DRM and the end-user license agreement will state that the contents of each call will be the property of Microsoft in perpetuity. Also, the Zellular Phone Call will only allow you to call someone three times. After that, every time you try to call that person you will hear a recording of a representative of the Recording Industry Association of America calling you a thief and yelling obscenities and threats at you.

Heh.

I would need an iAntacid

I am working at home this morning so that my hacking cough (getting better) does not disturb my coworkers. One benefit of doing this is being able to drink delicious, delicious home brewed coffee… so much better than the stuff from the single-serving machine at work. It is perhaps a good thing that our office does not have the Starbucks iCup machine (as seen at Microsoft). My already precarious digestive balance would be upset permanently.

Thanks to Jenni, whose blog I’m returning to after too long a hiatus, for the link.

Waiting for Vista…

I have a new laptop on the way at work, and, yesterday’s post notwithstanding, I’m looking forward to getting it so that I can load Windows Vista on it.

Why, you may rightly ask, would I want to do that to myself? Well, Vista is the first Microsoft OS in seven years that I haven’t used as my primary OS while it was in prerelease status, so I’m feeling a little behind the curve. But also it just feels like time. I’ve been using XP since 2001 in prerelease form (starting during my summer internship), and all the novelty of the new issues in XP has worn off. I’m tired of:

  • Long delays in the UI when booting and waiting for services to start
  • Long delays in the UI when switching from one network to another or into disconnected status
  • Bad power management during sleep (see yesterday’s post)
  • Weird screen switching behavior
  • Needing to reboot all the time
  • Three or more keystrokes to create a folder

Will any of this change in Vista? At this point, I have no idea, and that’s what I’m looking forward to exploring.

Windows Live Writer and Manila blogs

There’s a little virtual ink today about Windows Live Writer, a blog writing tool that launched on Friday and apparently uses the MetaWeblogAPI to publish to MSN Spaces or other blog authoring platforms. Interestingly, former ColdFusion guy JJ Allaire appears to be involved with this project, which to me suggests there’s more than meets the eye here: no way JJ would get involved with something that is only a blog publishing tool.

As always with these tools, I can’t test the auto-configuration feature because the version of Manila on my blog server doesn’t implement the getUsersBlogs method of the MetaWeblogAPI. Digging deeper it looks like the blog information is stored in the registry under HKEY_CURRENT_USERSoftwareWindows Live WriterWeblogs. So I created a profile for another site that used the MetaWeblogAPI and tried editing the values to point to my Manila site instead. I’ll know in a second if that worked. —Oh well. Attempts to post are failing with a message Can’t split the URL because it is not of the form ‘http://www.server.com/hello.html‘—I assume that this is referring to the RPC URL on Manila servers, which has no . extension or trailing slash but just appends /RPC2 to the top level domain.

Out of box functionality: no way to do HTML entity conversion is apparent (which is why this post doesn’t have curly quotes).

I think this tool would probably look and work better with a more modern blogging platform; the automatic WYSIWYG preview is pretty cool for blogging platforms that support it, for instance. But Flock still works better.

Why do DVRs suck: reliability or user experience?

A Microsoft friend of mine was quoted in a CNET article this morning (Why my cable DVR stinks). Arvind (whose last name was misspelled in the article) said (and this is something I’ve heard from him before) that the rich-client, local processing model that Windows Media Center uses is a much better way to provide DVR features than a networked DVR model such as the one Cablevision is trying. Aside from being consistent with Microsoft’s general vision of keeping the end nodes smart, I think Arvind has a point about the need for a “much richer user experience.” Certainly a graphical UI is easier to sort through when deciding what to watch than a text listing, even a well designed one—especially in a 30 foot UI.

I think the bigger issue is the reliability one, and here Arvind may have overstated his point, which appears to be that Vista is a step on the way to reliability nirvana. I don’t care how reliable media center PCs are running Vista. They just have to be more reliable than the equivalent set-top hardware, including Tivos and Comcast’s proprietary DVR. (We had two total Comcast DVR meltdowns before we gave up and went Tivo.)

The problem with the cable guys is that they refuse to acknowledge the need for moving the content off the box. Hey guys—RIAA vs. Diamond Multimedia showed that space-shifting content was legal seven years ago. Why does Comcast still make it impossible to get my content off their DVR? At least my new Tivo lets me burn shows to DVD, though I would prefer it if I could back up the hard drive directly over the network.

Congrats to Mark Russinovich and Sysinternals

Slashdot: Microsoft acquires Winternals and Sysinternals. Regardless of how you feel about Microsoft, this is great news for Winternals the company and Mark Russinovich the industry figure. (For those that don’t recognize the name, think Sony BMG: Russinovitch’s blog at Sysinternals blew the whistle on Sony BMG’s rootkit.)

It’s clear that this is a talent acquisition; Microsoft has said they are aware of some product overlap with Winternals’s product line, which generally means some sort of phased migration plan is in order.

I think the Slashdot advice to download the free Winternals utilities now is a very very good idea. I always forget that Regmon exists until I need it, and then I wonder how I lived without it.

I also find the statement that they’ll rationalize the Sysinternals community features with Microsoft.com offerings somewhat disturbing. If the value of Mark’s blog, for instance, is its refusal to spout the Microsoft party line and thus carrying a strong reputation for truthful investigation into technical issues, aren’t they destroying some value by bringing him into the fold? Or are they afraid of having another high-profile blogger get too much of an independent rep, as Scoble did?

A farewell to Gates

I haven’t said anything about Bill Gates’ announcement that he’ll be stepping out of day-to-day work over the next two years, yielding the chief architect reins to Ray Ozzie. Primarily it’s because my life has been pretty busy, but partly it’s because Gates has seemed, from the outside at least, like a non-factor in recent years. With Vista coming to market without big features like WinFS and several years overdue, and with Microsoft continuing to struggle to get customers to re-up for the newest versions of Office, it feels like Bill hasn’t had anything really new and compelling to show the market in a really long time.

Scott Rosenberg does a good job of connecting the dots in his supposition about Bill’s role in the Vista slip: on the one hand Bill had to watch as the scope of Vista was pared down and many revolutionary features were put aside, and on the other the culture that Bill and the Windows team had fostered meant that slips in the schedule were never acknowledged until it was far too late (thanks to Microsoft blogger Philip Su for some incisive and honest observations about the management culture in Windows).

My perspective from a greater distance is this: Bill and Steve Ballmer centralized Microsoft’s strategic decisions to an enormous degree, despite the generally broad operational freedom that individual product units enjoyed. And it’s not clear that that organizational move paid off. Might Microsoft be further along the path in dominating the enterprise software market—a place where the company does well with SQL Server and Exchange but has yet to make a splash with other business and IT apps despite years of investment—if the enterprise business had been able to duck the Windows tax? And by that, I mean the internal Windows tax that every business at Microsoft faces: every business has to show how it’s relevant to the corporate cash cow, and heaven forbid that the busines s plan suggests that the new initiative should embrace a multi-platform, multivendor view of the world instead of the Windows party line.

The result is that Gates rides off into the sunset as the champion of the desktop, but with many goals for Microsoft in the enterprise, on mobile devices, and in the home left unrealized. And with many users frustrated by years of vulnerabilities and diminishing returns.

Can Ray Ozzie turn this around? Maybe. He certainly has more enterprise cred than Bill. I’m not convinced that his vision is as broad as Bill’s, but that just might be a good thing for the long-term health of the company.

Welcome to the alumni club, Scoble

Boston Globe: Blogger who often rapped Microsoft will join a start-up. What a misleading headline. That’s like saying “Man who sent emails daily leaves company.” I saw Robert’s tweaking of Mr. Softie as an important part of his working to build credibility with tech influentials, the people whom Microsoft most needed to win over. If your employer does something stupid, and you are trying to model a behavioral pattern of honesty and transparency through public discourse, you don’t clam up, you call them on it. And Scoble did that, time and time again.

I appreciate Scoble’s honesty. A lesser man would have claimed credit for the groundswell of blogging that happened at the company during his tenure. Scoble wisely disclaims, “I’m not the only blogger at Microsoft. There are about 3,000 of them here. They are not having the plug pulled on them. They changed the world. I just was the cheerleader.” But by his very public risk taking, Scoble made the world safer for them against some old school Microsofties who wanted badly to take them down.

All of which is to say, it’s very odd that the Globe chose to print some random laptop-toting schmoe’s picture instead of Robert’s with the story. Too bad it’s not available on line. It gave me a good chuckle.