O'Reilly logo

Windows Presentation Foundation 4.5 Cookbook by Pavel Yosifovich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required