Steven Kirk bio photo

Steven Kirk

Preemptive nostalgia of the possible but doubtful.

Twitter Github

In the last post I described the first attempt at binding priorites in Perspex.

To see the problem with this simple system consider the following example:

var textBox = new TextBox();
textBox.Bind(TextBox.TextProperty, viewModel.WhenAnyValue(x => Text));
textBox.GetObservable(TextBox.TextProperty).Subscribe(x => viewModel.Text = x);

This creates a two-way binding between the TextBox.Text property and the viewModel.Text property. But there’s a problem. With the system described in part 1, local values are stored as bindings, as the PriorityValue is just a linked list of bindings.

Which means that a user typing into the TextBox overrides the binding setup above. So a binding would fire only once after user interaction and remain dormant from then on.

Clearly this isn’t desirable behavior.

The solution was that for each priority level, you need a “local value” : a value set using PerspexObject.SetValue that takes affect only until the next time a binding of the same priority fires.

And this is the story of how PriorityValue became a collection of PriortyLevels.

However, this isn’t the end of the story…