翻译自In WPF, how to debug triggers?
本来不想发的,但搜索了一下国内好像没人写这个,so…
效果如图
工作原理
使用附加属性将虚拟动画storyboards添加到触发器
激活WPF动画跟踪并将结果过滤到仅包含storyboards
TriggerTracing
将TriggerTracing
添加到项目中
/// <summary>
/// Contains attached properties to activate Trigger Tracing on the specified Triggers.
/// 包含附加属性以激活指定触发器上的触发器跟踪
/// This file alone should be dropped into your app.
/// 仅此文件应放入您的应用程序
/// </summary>
public static class TriggerTracing
{
static TriggerTracing()
{
// Initialise WPF Animation tracing and add a TriggerTraceListener
//初始化WPF动画跟踪并添加TriggerTraceListener
PresentationTraceSources.Refresh();
PresentationTraceSources.AnimationSource.Listeners.Clear();
PresentationTraceSources.AnimationSource.Listeners.Add(new TriggerTraceListener());
PresentationTraceSources.AnimationSource.Switch.Level = SourceLevels.All;
}
#region TriggerName attached property
/// <summary>
/// Gets the trigger name for the specified trigger. This will be used
/// to identify the trigger in the debug output.
/// 获取指定触发器的触发器名称。 这将用于在调试输出中标识触发器。
/// </summary>
/// <param name="trigger">The trigger.</param>
/// <returns></returns>
public static string GetTriggerName(TriggerBase trigger)
{
return (string)trigger.GetValue(TriggerNameProperty);
}
/// <summary>
/// Sets the trigger name for the specified trigger. This will be used
/// to identify the trigger in the debug output.
/// 设置指定触发器的触发器名称。 这将