This post describes a new technique for debugging triggers allowing you to log all trigger actions along with the elements being acted upon:
It's good because it:
- helps you fix all manner of problems :)
- works on all types of trigger: Trigger, DataTrigger, MultiTrigger etc.
- allows you to add breakpoints when any trigger is entered and/or exited
- is easy to set up: just drop one source file (TriggerTracing.cs) into your app and set these attached properties to the trigger to be traced:
<Trigger my:TriggerTracing.TriggerName="BoldWhenMouseIsOver" my:TriggerTracing.TraceEnabled="True" Property="IsMouseOver" Value="True"> <Setter Property="FontWeight" Value="Bold"/> </Trigger>
It works by:
- using attached properties to add dummy animation storyboards to the trigger
- activating WPF animation tracing and filtering the results to only the entries with the dummy storyboards
Download sample app with source code
4 comments:
Awesome! Thanks for sharing, just what I needed. Attached properties are usefull in a lot ways. I never thought of using them inside triggers.
Perfect! Amazing! Thank you so much for sharing this with the community.
Superb.... You made my life easy
-Amar
Animation storyboards are a really cool and orignal way to achive this, I don't think I would have thought of that in a million years!
Thanks.
Post a Comment