Exposing events from a User Control
In the previous recipe, we learned about User Control, how to create it, and how to expose a dependency property and utilize it. In this recipe, we will learn how to expose events from a User Control, as you will need it in most cases.
Getting ready
Let's open the same project, CH05.UserControlDemo
, inside the Visual Studio to proceed with this recipe.
How to do it...
To demonstrate the usage of the event, we will add two buttons inside our ColorMixer
User Control and expose the OK
and Cancel
button events from it. To implement the same, perform the following steps:
- Open the
ColorMixer.xaml
file and add the followingStackPanel
inside theGrid
, which will place it at row index1
and column index0
. The panel consists of two buttons with labelsOK
andCancel:
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="4 10 4 4" HorizontalAlignment="Right"> <Button...