CSTK6667
CSTK6667

Reputation: 1

Custom RoutedEvent in WPF

In WPF, I want to create a custom routing event which is used when the data is greater than a value, the light will start blinking (similar to an alarm) and when the value is lower than a value, the light will go back to its previous state.

 <EventTrigger RoutedEvent="Button.Click" SourceName="btn">
            <BeginStoryboard Storyboard="{StaticResource Blink}"/>
        </EventTrigger>

I used a storyboard to realize the blinking of the light, using Eventtrigger as the trigger, which accepts a RoutedEvent.I have checked many examples on the web and they all involve creating a new custom control (e.g. a custom button) and then customized click events.I would like to ask how to build a custom RoutedEvent to implement my light blinking function, or is there a better way (without using routed events).

Upvotes: 0

Views: 42

Answers (1)

sokolik745
sokolik745

Reputation: 21

I am not sure what you want to achieve by using button click event because you are writing about data level which should trigger the animation.

Assuming that you are using MVVM pattern I would use the DataTrigger instead and combine it with your custom converter. The converter would convert the data value to the bool according your level value. How to create your own converter you can find here.

Then you could use DataTrigger and use this trigger in binding to your value property. Here you can see an example in other question. Do not forget to stop the animation.

Upvotes: 0

Related Questions