Custom RoutedUI Commands In WPF
In this article we will see how we can use Custom RoutedUI Commands in WPF.
Creating A WPF Project
Fire up Visual Studio 2008, create a WPF Application, and name it as CustomCommandRoutedUI.
Now let’s create a static class in Window1.xaml.cs
As you see in above code display, we have created a static class with 3 static readonly commands of type RoutedUICommand.
Now to use it in XAML behind we need to add the namespace.
Let’s have three buttons such Add, Edit and Copy. Which would operate on a ListBox item.
So let’s do the design.
The following is the reference for the XAML.
Now let’s have the Commands Binding for the ListBox.
As you see in above XAML display we have the Commands attached and we handled two events such as CanExecute and Executed for all the Commands.
Now let’s set the CommandTarget and CommandParameter wherever required.
Now let’s have the events handled.
Let’s have the Add Command first.
Then similarly Delete Command.
And finally Copy Command.
That’s it. Let’s run the application and see how we managed to use CustomRoutedUI Commands.
Hope this article helps.