Handling standard commands in a user control

A typical user control exposes properties and events, but it can also handle commands. These can be standard commands (RoutedUICommands defined by WPF) or custom commands exposed as properties and invoked by the control. In this recipe, we'll see how to add command handling to a user control.

Getting ready

We'll use the projects we created in the previous recipe, Creating a user control, so make sure the solution is open.

How to do it...

We'll add handling for the standard MediaCommands.ChannelUp and MediaCommands.ChannelDown commands. ChannelUp will increase each of the RGB values and ChannelDown will decrease them.

  1. Open ColorPicker.xaml.cs. Add a static constructor to the class that registers for command ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.