增加实时状态保存

This commit is contained in:
ww-rm
2025-10-17 22:41:49 +08:00
parent b178e48e84
commit 02445d36e5
5 changed files with 191 additions and 84 deletions

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace SpineViewer.Utils
{
public static class PropertyWatcher
{
public static IDisposable Watch(DependencyObject target, DependencyProperty property, Action callback)
{
var dpd = DependencyPropertyDescriptor.FromProperty(property, target.GetType());
if (dpd == null) return null;
EventHandler handler = (s, e) => callback();
dpd.AddValueChanged(target, handler);
return new Unsubscriber(() => dpd.RemoveValueChanged(target, handler));
}
private class Unsubscriber : IDisposable
{
private readonly Action _dispose;
public Unsubscriber(Action dispose) => _dispose = dispose;
public void Dispose() => _dispose();
}
}
}