Click here to Skip to main content
15,566,520 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using this example to do textbox validation. Here is the code.
<Style TargetType="{x:Type TextBox}">
        <Setter Property="Validation.ErrorTemplate">
                    <DockPanel LastChildFill="True">

                        <TextBlock DockPanel.Dock="Right"
                            Text="{Binding ElementName=MyAdorner, 

                        <Border BorderBrush="Green" BorderThickness="3">
                            <AdornedElementPlaceholder Name="MyAdorner" />

            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip"
                    Value="{Binding RelativeSource={RelativeSource Self}, 


Now I am going to add a mouse click even to it. Also I want to move this style to the a separate style file.

The question is that resource file can't have event in it. How?

What I have tried:

Find this one.
But it seems to use code behind something like. It might be okay. However I want the template can be re-useful.
Updated 21-Nov-17 20:04pm

1 solution

There are a number of different types of Triggers that you can use. In your example, you are using a Data Trigger. For Event, you need to use an EventTrigger.

I wrote an WPF article earlier this month about a ToggleSwitch control. In it I share an example of replicating the Notification Settings screen from Windows 10. In the article XAML code snippet I show how to use the EventTrigger for MouseOver. This is an ideal example for you: Flexible WPF ToggleSwitch Lookless Control in C# & VB[^] - download the code and you can see how it works.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900