C# Lifecycle User Control Promote Demote

C# Lifecycle User Control Promote Demote

Yesterday I created a User Control for a simple Life Cycle graph (here), I though it would be fun to add some user input to allow Promotion and Demotion, to do this I’m going to use the Messaging Class I talked about early this week (here).

Status Model

Since the Context Menu that will provide a Promote and a Demote option interacts directly with the Status Model, we must add our command methods here. Additionally in the constructor I’m passing in the Messenger object, so I can use the Send method.

C#

Commands Base

I use the following Commands Base for all of my Commands.

C#

Messages

To send a Promote or Demote message we will need to create two new record objects for the Promote and Demote Messages, and in both cases well pass back the current selected Status Model, so we know which status model must become active and inactive

C#

View Model

In the View Model we will subscribe to the Two Messages and create two methods to handle the Promotion and Demotion.

C#

StateUC.XAML

in the first user Control that defines the TextBlock we will add a ContextMenu to the Border tag, for Promote and Demote and Bind them to the two Commands in the Status Model.

XAML

Final Result

Now when we Right Mouse Click on each of the Nodes we can Promote and Demote the Status of the Life Cycle.

Promote Demote

Below we can see that the lifecycle has been promoted to Busy.

Busy Status

Controlling the Visibility of the Context Menu

We only really need to display the context menu on the Active Status Node. We can do this by creating a Context Menu Style and Data Trigger, that is bound to the Status State in the Status Model.

XAML

We can take this one step further by adding an extra int property into the Status Model. If the Value is -1 its the first node, if the value is 1 its the last node and if the value is 0 its a node in-between. I’m sure there is a better way to do this but its late.


We can then add the additional Data Triggers.

XAML

The result we get is.