Friday, June 26, 2009

WPF: Sorting Sets of Simple Strings

I've been doing a fair bit of WPF coding recently, and it's a compelling experience. The thing is, it isn't easy, and I think that surprises some people. Part of the reason for this is that the documentation still feels incomplete, in that undocumented kind of way. But the other reason is that it forces you to think very abstractly, all the time. If I were to think of a decent analogy, it would be one involving cooking: Coding in most UI toolkits is like cooking with lots of pre-made dishes (pre-cooked noodles, microwave dinners, pasta sauces out of the bottle.) Sure, you can make a decent meal, but the results are pretty predictable and maybe not that satisfying. Coding in WPF is like cooking with real ingredients - it can be challenging, and you can certainly mess up the results, but you can also whip up something fantastic.

That said, I thought I might pass along a tip for something that seems like it should be quite easy, but the documentation makes it unclear. I needed to produce two comboboxes for some UI, both of which contain lists of Strings. For one combobox, I needed a custom sort pattern, and for the second one I needed a straight up sort.
I'm finding that there are a bunch of ways to do this. You can create a List<> object that contains the strings, call Sort() on it, then bind it. However, that might not be an adequate solution since you're re-arranging your internal data and you may want to preserve its original order.
The other way of doing this is to apply a SortDescription to the Items list of your combobox or ListView. A SortDescription is pair consisting of a String which describes the property to sort on, and a sort order (ascending or descending.)
Now here's a little tip I just figured out: Most examples explain how to Sort a list of items that are bound to the control, by specifying the property name of the property to sort the content on.
    new SortDescriptions("Content", ListSortDirection.Ascending));
But what if your items don't have a sub-property? You may have guessed the answer, but I am hear to confirm that if you pass an empty string as the first parameter to the SortDescription, then it will apply the SortDirection to the Items themselves:
    new SortDescriptions("", ListSortDirection.Ascending));
And voila! For the second combo where I needed a custom sort, I simply did my sort on the items themselves beforehand then added them in the right order.


Friday, June 5, 2009

E3: Let's Get Physical

Seems like the latest E3 was full of surprises... or maybe not. With Nintendo's raging success in the video game market due to its unconvential Wii, you'd have to expect that both Microsoft and Sony would have to respond. They are now officially playing catch-up, and introduced their takes on the genre at the electronics tradeshow.
Microsoft gave a rather bold live demo of its newly acquired Project Natal, a smart camera that can motion-capture participants using a single camera device. This may sound like a gimmick, but the demos are surprising and effective. Included in the system are both image and voice recognition systems that are used to recognize the current user and interpret commands, respectively. I think the possibilities just for the social and device browsing features are pretty cool - built in voice and video chat, voice-activated, as well as being able to browse to your favourite downloaded media using hand motions. Kind of makes Minority Report seem a little clunky, actually.
Probably the most impressive demonstration of the technology is the Milo video, featuring Lionhead and Peter Molyneux.
Thanks to Trevor, who pointed out that Penny Arcade has the best take on Natal:
And then there was the PS3, that stayed with the conventional, and yet refined Nintendo's motion controller with one that appears to be much, much more sensitive. I think this is actually a pretty smart move on their part, since they are now working with a refinement on a proven technology. It remains to be seen whether they can get these controllers to the 15 million or so install base that the PS3 currently enjoys.
I found the handwritting demo to be the most effective. I mentioned to a collegue that the token Sony Demo Geek could write better in virtual space than I can on paper.
And finally, there was Nintendo. You'd think that the company that revolutionized and galvanized the gaming industry would want to follow that up with something that would keep them one step ahead of the competition. With that in mind, Nintendo unveiled Vitality, which is basically a heartbeat sensor that attaches to your finger. “...Intends to have you see the information relating to the inner world of your body," is the quote from Satoru Iwata, president of Nintendo. At this rate, you can soon expect an electronic rectal thermometer from the esteemed "gaming" company in the coming years. With force feedback.


  © Blogger templates The Professional Template by 2008

Back to TOP