WPF 调试触发器

本文介绍了如何在WPF中调试触发器的工作原理,通过TriggerTracing实现对虚拟动画storyboards的跟踪。当将DebugTriggers附加属性添加到触发器时,可以在输出窗口观察其激活和停用状态。
摘要由CSDN通过智能技术生成

翻译自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.
    /// 设置指定触发器的触发器名称。 这将
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值