Reactive Extensions, ReactiveUI, and Whistling Tea Kettles

How does reactive programming work? “It’s all streams,” our program manager explained. “When you update a property in one part of the system, it causes another property in a different part of the system to update, too. It will take a bit to wrap your mind around.”

In my head, I pictured properties all over the system “magically” updating when a user clicks a button. Due to the lack of magic in programming, this mental image was not a complete picture—but it’s not that different from how reactive programming actually works.
Read more on Reactive Extensions, ReactiveUI, and Whistling Tea Kettles…

Functional(ish) C# & MVVM: Single-Responsibility and Code-as-Data

I’ve spent the last year working in C# and WPF. Over a few blog posts, I have alluded to a particular pattern of structuring code, referring to it as “stateless single responsibility” objects or “stateless SRP” objects. For the purposes of this post I will call the pattern “stateless single responsibility principle” (SSRP) objects. I’d like to go into a bit more detail about what the pattern is and why I use it.

I think it will be simplest to begin with an example problem we might use my pattern to solve, then show how I would do it and explain all the parts. Read more on Functional(ish) C# & MVVM: Single-Responsibility and Code-as-Data…

Toggle the Visibility of a Text Run in WPF

I ran into a situation the other day where I had to turn on/off the visibility of a text run in WPF, and I discovered that text runs do not have a visibility property. 

Whenever I run into a situation where I need to add functionality to a control, I always turn to attached properties as my go-to tool. Here is a quick and easy way to add the visibility functionality using an attached property.

Read more on Toggle the Visibility of a Text Run in WPF…

Spying on Your WPF Applications with Snoop

If you’re developing WPF applications and do not have Snoop installed; install it now. I’ll wait. Installed? Good.

Snoop is an open source tool for spying and debugging a running WPF application. It can be used to inspect your running application and make changes while your app is still running. I’ve found it to be very useful for finding missing bindings and tweaking layout parameters when you can’t use Designer. (don’t ask, that’s a blog post for another day.)

Here are a few tips to get you started:

Selecting Your App

After installing and launching Snoop, drag the cross-hairs from the Snoop window to your WPF application. You’ll see your application tree on the left and a property editor on the right for whatever component you have selected.

Read more on Spying on Your WPF Applications with Snoop…

How To Debug Data Binding Issues in WPF

Data binding establishes a connection between the application UI and business logic. When it works, it’s a wonderful thing. You no longer have to write code that updates your UI or pass values down to your business logic. When it breaks, it can be frustrating to figure out what went wrong. In this post, I will give you some tips on how you can debug your data bindings in WPF.

1. Add Tracing to the Output Window

Here is a sample TextBlock that has a missing data context. In this situation, you will not get any errors in the Visual Studio output window.

Read more on How To Debug Data Binding Issues in WPF…

WPF RadioButtons: Choices, Choices

Radio buttons are a common way for a user to select a single choice from several options. In this post, I’ll go over several ways of using RadioButtons in the Microsoft .Net Windows Presentation Foundation (WPF) framework.

The Basic RadioButton

The first thing to know about WPF RadioButtons is that, unless otherwise specified, all RadioButtons within a container element (e.g. Grid, StackPanel) are assumed to be members of the same group. So a simple way to include a group of RadioButtons in a view is to do something like this: Read more on WPF RadioButtons: Choices, Choices…

You Can Write Inline C# in XAML – But Should You?

Did you know that you can write inline C# in your XAML file with the x:Code Intrinsic type? When I stumbled on this feature, my first reaction was, “Wow, I didn’t know you could do that!”  After several years of using WPF, I thought I knew all the tricks. Discovering something new was exciting!

The initial thrill was tempered once I thought about it, however, and I was soon saying, “Oh no, people should never use this!” I generally keep an open mind about code, because even if it doesn’t fit my immediate needs, I know someone might find it useful. With inline C#, however, I am slightly bewildered that this feature was ever considered useful enough for Microsoft to include. Read more on You Can Write Inline C# in XAML – But Should You?…

Reactive Extensions + WPF? Yes, Please

In my recent post on IObservables, I discussed augmenting the ReactiveExtensions library with the ability to “cache” a Select() call. One of the ways I am using this in my current project is to provide the same data to multiple UI elements. Sadly, WPF does not directly support IObservable for data binding. However, with a little effort you can use IObservable very effectively as a data source for your ViewModels.

Read more on Reactive Extensions + WPF? Yes, Please…

Complicated UI Widgets in WPF

One of the pleasant surprises I encountered while using WPF was how easy it is to change the look of a button. It is very easy to draw buttons using simple shapes, rounded corners, and so on. Sometimes, though, your application’s needs will require more complicated work.

For example, say you need to make an image similar to a wifi logo, like so:

How might you go about this in WPF?

Read more on Complicated UI Widgets in WPF…

Using XAML to Set Focus on a Textbox in WPF Desktop Applications

Recently, I have been using WPF to give a .NET desktop application its own customized look and feel that matches my client’s product branding.

In one of the workflows I implemented last week, the user inputs a 4-digit passcode that allows them to connect to an external device.

Here is a diagram of the workflow we needed to implement:

Read more on Using XAML to Set Focus on a Textbox in WPF Desktop Applications…