Adam Sills Archive  rss

Programming Windows, 6th Edition eBook–Available Now

Charles Petzold is returning with a 6th edition of his Programming Windows book, this time focused on Windows 8. XAML, WinRT, MVVM and other Windows 8 specific topics. His last update to this series was 1998. If you’ve been putting off learning the WPF/Silverlight/WinRT style of application building via XAML, O’Reilly has a great deal for the next two weeks. Order the eBook today, for $10, and you’ll get it today based on the Consumer Preview, then when it’s updated for Release Preview you’ll get that, then when it’s released finally you’ll get the book based on the Released version

Best Quote From Build

After all the hullabaloo around the “HTML5 on Win8, Microsoft is abandoning Silverlight!”, it’s nice to have a quote like this (2:11:00 here) to stop all the sky is falling talk. “…all of your knowledge around XAML, around C#, around Silverlight and all that stuff, it just carries straight across to here …”

Converters–Part 1–Simple Code-behind Based Converter

Silverlight projects I’ve been a part of tend to develop a robust set of converters. Anything I can do to keep my view model in a relatively pure state (see Part 0 for more details) keeps me happy. However there are times when I also don’t want to write a converter for one simple “throw-away” data conversion. I know I’m not likely to reuse this and I know I also don’t want to change my view model for this one conversion either. Instead, I’ve been using a simple “Code behind converter” where you can specify your conversion code in the

Fixing ComboBox.SelectedValue Bug with Expression Behaviors

Happened upon a Silverlight bug today. In essence, if you have a ComboBox with its SelectedValue bound to a property and set that property to null, the ComboBox throws out your binding. No, really. There’s even a Connect bug about it. For posterity, here is an incredibly simple reproduction scenario. No view models or anything fancy, just one user control: This code sets up a ComboBox with the appropriate settings, a TextBlock bound to the same property as the ComboBox’s SelectedValue

Converters–Part 0–My View on MVVM and Converters

Converters are a bit of a touchy subject in MVVM. Some would argue that the ViewModel is itself a “converter on steroids” and for the most part I agree, specifically when you are dealing with complex values (“I have an object of type Contract but I want to display a Customer on screen”). My view of MVVM is within view of the dogmatic MVVM, however I also have a strong pragmatic voice in my head telling me not to go overboard on things. So while I do think that a view model should closely resemble the data a view needs,

Useful Expression Blend SDK Controls–LineArrow

The Expression Blend SDK has some interesting controls in it that you can easily miss if you’re not poking around the SDK namespaces. The one I’m going to talk about right now is called LineArrow and is a simplistic way to draw a curved or straight line with optional arrow heads on it. At its simplest, it draws a line from one corner of itself to another corner: And when executed it looks like this: To put this to good use, one

Useful Expression Blend SDK Controls–Callout

The Expression Blend SDK has some interesting controls in it that you can easily miss if you’re not poking around the SDK namespaces. The one I’m going to talk about right now is called Callout. The Callout control is a content control that renders itself with an optional arrow anchored at a given point. What makes this control interesting (and fun) is it has an option for a displaying itself light a thought bubble and a word balloon. The AnchorPoint property dictates where the optional arrow will be anchored on the callout. The CalloutStyle property has 4 options: Cloud,

Creating Your Own XML Namespaces for Silverlight

When you need a visual element from anywhere other than the main Silverlight namespaces/assemblies, it can be a pain to register namespaces. If I want a control from the Silverlight toolkit System.Windows.Layout.Toolkit assembly: These are a pain because either you wait for Intellisense to pop up once the cursor is inside the quotation marks (I’ve noticed some don’t even realize Intellisense works here as it can sometimes take so long to open) or you memorize the format. You can also use Resharper, but that defeats the purpose of what I’m about to discuss. Once I have registered my namespace

Expression SDK in Silverlight–DataTrigger Example

One type of Trigger available in the Expression SDK is the DataTrigger. This a trigger that uses a Binding to determine when to execute its actions. If you are using MVVM (or any other pattern that relies heavily on view models or presentation models), this class is a perfect way to interact with the UI without needing to write any custom code in the model or codebehind. For the purpose of this post, I’m going to be creating a simple header/button control that is powered by a view model and alters the user interface of the control based on data

Behaviors in Silverlight with the Expression SDK

Prior to the Expression SDK, you had two main choices to create reusable behaviors that could be applied to UI elements. First and most obvious is to subclass a control type and add whatever functionality you wanted. For instance, if you wanted a TextBox to raise an event (or execute an ICommand) whenever the Enter key was pressed, you could create a subclassed TextBox and add that. The second way was to create manual “attached behaviors” via a trick commonly used in WPF with attached properties. In short, you create an attached property and use the property change notification to