A Context-Sensitive Help Provider in Wpf

Here’s an example of a way to add context-sensitive help to your application.  The main idea is to simply use the built-in ApplicationCommands.Help command.  This command is already tied to the F1 key, and so executes when you hit F1, and tells your command handler what element the user was on when it was hit….


A look at stretchy elements

There are several elements in Wpf that have a “Stretch” property.  The basic idea of these properties is to allow you to specify how an element adapts itself to a layout container, such as a Grid.  For example, if you have a 100×200 pixel image, and it’s being positioned in a 150×300 pixel cell in…


Building read-only objects in Xaml

We often use Xaml to instantiate and initialize objects.  For example, given “<Foo Bar=’1’/>”, a Xaml loader creates a Foo object, and sets the Bar property to 1.  That works when the Bar property is settable, but what can you do if it isn’t?   An example of this scenario in .Net today shows up…


Two ProgressBar Tricks

Here’s a couple of handy ProgressBar tricks …   The first trick is to use a negative Minimum value, so that as soon as a ProgressBar starts, you give the user the visual feel that the progress has already begun.  This is especially useful if, in your scenario, it takes a couple of seconds to…


Namespaces in Xaml

If you’re really into Xml conformance, and you’ve really wondered how Xaml uses Xml namespaces, read on; I can cover the most relevant details in 1160 words or less …   Namespaces on tags   (I’m using the term “tag” here instead of the more correct term “element”, so that I don’t get confused with…


Expandos in xaml

This post has a couple of suggestions on ways to accomplish expandos in Xaml.  First some background …   On an HTML page you can define your own new “expando” properties on the fly, such as in this example:   <HTML>   <BODY onload=‘paragraph1.innerText = paragraph1.testing‘>     <P ID=‘paragraph1‘ testing=‘1, 2, 3‘/>   </BODY> </HTML>…


Where does a Binding find its data?

If you’ve look at much WPF Xaml you’ve probably seen bindings like this:   <TextBlock Text=“{Binding Name“ />   … which binds the Text property of the TextBlock to the Name property of some data object.   The question that begets is:  where does the data come from?  The rest of this post looks at…


How to target a template setter at non-element content

Here’s a technique you can follow to use property triggers in a template on non-element type objects.  First, though, some background on what that means …   Take this example of a Button with a custom template which is simply a rectangle:   <Button>   <Button.Template>     <ControlTemplate TargetType=“Button“>       <Rectangle Width=‘60‘ Height=‘40‘ Fill=‘Red‘ x:Name=‘MyRectangle‘>…


Tip: Using XamlWriter and XamlReader to clone an object

There are multiple ways to clone objects, and multiple definitions of what “clone” should even mean.    The main issue is usually about cloning “deep” vs. “shallow”.  For example, if you have a Customer object that points to an Address object, and you clone the Customer object, does the Address object get cloned too (this…


Parameterized templates; and how to create reusable, custom-looking buttons without code

I’ve talked to a few people recently about parameterized templates, and so I wanted to write some of it down.  Here’s the scenario … I want to create an application that has a main window with several buttons on it.  Clicking one of the buttons navigates you to part of an app.  For example, in…