What is XAML StatusBar

The Perfect WPF StatusBar

24 Oct 2007

Last night I was trying to incorporate a status bar into my WPF shell. It turns out getting the perfect behaviour wasn’t as straightforward as I’d hoped, so I thought I’d elaborate here.

The simplest status bar is straightforward and looks just fine:

The markup for this is:

Now suppose you want to add a second panel (I wanted more, but I’ll get to that). You might try:

But this may not render how you were expecting:

Typically you would want the left-most panel to stretch. Turns out the s are hosted in a , so you can do this just by setting the property on the right panel:

But notice something else: we had to switch the order of the s so that the first one fills the remaining space. This is because of the way WPF’s works. The last item present in it will fill remaining space unless you tell it otherwise.

It’s a bit confusing having the second item first, and things get worse as we add more and more items. Moreover, we don’t have sufficient control over the proportional widths allocated to the status bar items.

We need more control over how the s are arranged. The key to this problem is that the ’s use of a for layout is a default only. Like most things WPF, it can be customised. We can do this via the property. This is actually a property of the class, which inherits from. However, does override the default panel type, changing it from to .

For the ultimate control, I opted to use a , WPF’s swiss army knife panel. For example:

With this markup we get:

Of course, being WPF you can add whatever you want to the status bar, including separators, images, or whatever. The point is, for more control over the layout of your s, you’ll want to swap out the default for something with more oomph.

If you would like to discuss how I can help you with mobile app development (Xamarin/Flutter), back-end development, C#, Dart, .NET Core, Azure, Firebase, Google Cloud Platform, or reactive programming then please get in touch.

comments powered by