Debugging triggers is a painful process: they work behind the scenes, there's nowhere to put a breakpoint and no call-stack to help you. The usual approach taken is trial and error based and it nearly always takes longer than it should to work out what's going wrong.
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
Không có nhận xét nào:
Đăng nhận xét