<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      C# avalonia沒有內(nèi)置判斷屬性是否綁定的代碼,所以我們自己擴展實現(xiàn)一個。這個擴展可以用于動態(tài)解綁和綁定屬性。基于我寫的自定義擴展。

      http://www.rzrgm.cn/dalgleish/p/18972924
      

      AvaloniaObjectExtensions代碼

      using Avalonia;
      using Avalonia.Data;
      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.Linq;
      using System.Reflection;
      using System.Text;
      using System.Threading.Tasks;
      
      namespace Shares.Avalonia
      {
          public static class AvaloniaObjectExtensions
          {
              private static readonly MethodInfo? getExpressionMethod;
              private static readonly FieldInfo? valuesField;
              private static readonly FieldInfo? framesField;
              private static readonly FieldInfo? localValueBindingsField;
              private static readonly Type? valueEntryType;
      
              static AvaloniaObjectExtensions()
              {
                  var baseAssembly = typeof(AvaloniaObject).Assembly;
                  var valueStoreType = baseAssembly.GetType("Avalonia.PropertyStore.ValueStore");
                  valueEntryType = baseAssembly.GetType("Avalonia.PropertyStore.IValueEntry");
      
                  getExpressionMethod = valueStoreType?.GetMethod("GetExpression",
                      BindingFlags.Instance | BindingFlags.Public,
                      null, new[] { typeof(AvaloniaProperty) }, null);
      
                  valuesField = typeof(AvaloniaObject).GetField("_values", BindingFlags.Instance | BindingFlags.NonPublic);
                  framesField = valueStoreType?.GetField("_frames", BindingFlags.Instance | BindingFlags.NonPublic);
                  localValueBindingsField = valueStoreType?.GetField("_localValueBindings", BindingFlags.Instance | BindingFlags.NonPublic);
              }
      
              public static bool IsBinding(this AvaloniaObject avaloniaObject, AvaloniaProperty property)
              {
                  try
                  {
                      if (avaloniaObject == null || property == null) return false;
                      var valueStore = GetValueStore(avaloniaObject);
                      return valueStore != null &&
                             (TryGetExpression(valueStore, property, out var expr) && expr != null
                              || IsLocallyBound(valueStore, property)
                              || IsBingdingInFrames(valueStore, property));
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine($"[AvaloniaObjectExtensions] IsBinding錯誤 : {ex.Message}");
                      return false;
                  }
              }
      
              public static bool RemoveBinding(this AvaloniaObject avaloniaObject, AvaloniaProperty property)
              {
                  try
                  {
                      if (avaloniaObject == null || property == null) return false;
                      var valueStore = GetValueStore(avaloniaObject);
                      if (valueStore == null) return false;
      
                      var currentValue = avaloniaObject.GetValue(property);
                      bool removed = RemoveLocalBinding(valueStore, property)
                                  || RemoveFrameBindings(valueStore, property)
                                  || RemoveBindingExpression(valueStore, property);
      
                      if (removed) avaloniaObject.SetValue(property, currentValue);
                      return removed;
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine($"[AvaloniaObjectExtensions] RemoveBinding錯誤 : {ex.Message}");
                      return false;
                  }
              }
      
              private static object? GetValueStore(AvaloniaObject obj) =>
                  valuesField?.GetValue(obj) ?? obj.GetFieldValue<object>("_values");
      
              private static bool TryGetExpression(object valueStore, AvaloniaProperty property, out object? expression)
              {
                  expression = null;
                  try
                  {
                      expression = getExpressionMethod?.Invoke(valueStore, new object[] { property });
                      return expression != null;
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine($"[AvaloniaObjectExtensions] TryGetExpression錯誤 : {ex.Message}");
                      return false;
                  }
              }
      
              private static bool IsLocallyBound(object valueStore, AvaloniaProperty property)
              {
                  try
                  {
                      var localBindings = localValueBindingsField?.GetValue(valueStore) as IDictionary
                                          ?? valueStore.GetFieldValue<IDictionary>("_localValueBindings");
                      return localBindings?.Contains(property.GetPropertyValue<int>("Id")) == true;
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine($"[AvaloniaObjectExtensions] IsLocallyBound錯誤 : {ex.Message}");
                      return false;
                  }
              }
      
              private static bool IsBingdingInFrames(object valueStore, AvaloniaProperty property)
              {
                  try
                  {
                      var frames = framesField?.GetValue(valueStore) as IList
                                   ?? valueStore.GetFieldValue<IList>("_frames");
                      if (frames == null) return false;
      
                      foreach (var frame in frames)
                      {
                          int entryCount = frame.GetPropertyValue<int>("EntryCount");
                          for (int i = 0; i < entryCount; i++)
                          {
                              try
                              {
                                  var entry = frame.InvokeMethod("GetEntry", new object[] { i });
                                  if (entry != null && valueEntryType?.IsInstanceOfType(entry) == true && IsBindingEntry(entry, property))
                                      return true;
                              }
                              catch (Exception ex)
                              {
                                  Console.WriteLine($"[AvaloniaObjectExtensions] IsBoundInFrames (loop)錯誤 : {ex.Message}");
                              }
                          }
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine($"[AvaloniaObjectExtensions] IsBoundInFrames錯誤 : {ex.Message}");
                  }
                  return false;
              }
      
              private static bool IsBindingEntry(object entry, AvaloniaProperty property)
              {
                  try
                  {
                      if (!property.Equals(entry.GetPropertyValue<AvaloniaProperty>("Property")))
                          return false;
      
                      string typeName = entry.GetType().Name;
                      return typeName.Contains("Binding", StringComparison.OrdinalIgnoreCase) ||
                             typeName.Contains("Observer", StringComparison.OrdinalIgnoreCase);
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine($"[AvaloniaObjectExtensions] IsBindingEntry錯誤 : {ex.Message}");
                      return false;
                  }
              }
      
              private static bool RemoveLocalBinding(object valueStore, AvaloniaProperty property)
              {
                  try
                  {
                      var localBindings = localValueBindingsField?.GetValue(valueStore) as IDictionary
                                          ?? valueStore.GetFieldValue<IDictionary>("_localValueBindings");
                      var propertyId = property.GetPropertyValue<int>("Id");
      
                      if (localBindings?.Contains(propertyId) == true)
                      {
                          if (localBindings[propertyId] is IDisposable disposable)
                              disposable.Dispose();
      
                          localBindings.Remove(propertyId);
                          return true;
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine($"[AvaloniaObjectExtensions] RemoveLocalBinding錯誤 : {ex.Message}");
                  }
                  return false;
              }
      
              private static bool RemoveFrameBindings(object valueStore, AvaloniaProperty property)
              {
                  bool removed = false;
                  try
                  {
                      var frames = framesField?.GetValue(valueStore) as IList
                                   ?? valueStore.GetFieldValue<IList>("_frames");
                      if (frames == null) return false;
      
                      foreach (var frame in frames)
                      {
                          if (frame == null) continue;
      
                          var removeMethod = frame.GetType().GetMethod("Remove",
                              BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                              null, new[] { typeof(AvaloniaProperty) }, null);
      
                          if (removeMethod != null)
                          {
                              try
                              {
                                  removeMethod.Invoke(frame, new object[] { property });
                                  removed = true;
                              }
                              catch (Exception ex)
                              {
                                  Console.WriteLine($"[AvaloniaObjectExtensions] RemoveFrameBindings (invoke)錯誤 : {ex.Message}");
                              }
                          }
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine($"[AvaloniaObjectExtensions] RemoveFrameBindings錯誤 : {ex.Message}");
                  }
                  return removed;
              }
      
              private static bool RemoveBindingExpression(object valueStore, AvaloniaProperty property)
              {
                  try
                  {
                      if (TryGetExpression(valueStore, property, out var expression) &&
                         expression is IDisposable disposable)
                      {
                          disposable.Dispose();
                          return true;
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine($"[AvaloniaObjectExtensions] RemoveBindingExpression錯誤 : {ex.Message}");
                  }
                  return false;
              }
          }
      } 
      posted on 2025-08-05 07:04  dalgleish  閱讀(22)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 亚洲欧美在线观看品| 久久青草国产精品一区| 欧美国产日产一区二区| 日本边添边摸边做边爱| 成人久久精品国产亚洲av| 久久久这里只有精品10| 青草99在线免费观看| 精品久久久久久中文字幕| 国产精品视频一区二区三区不卡 | 日本精品极品视频在线| 五月国产综合视频在线观看| 亚洲第一极品精品无码久久| 亚洲精品日韩久久精品| 天堂资源国产老熟女在线| 无码电影在线观看一区二区三区| 91亚洲国产三上悠亚在线播放 | 欧美大bbbb流白水| 久久精品无码精品免费专区| 亲子乱aⅴ一区二区三区| 久久超碰色中文字幕超清| 日本特黄特黄刺激大片| 国产在线啪| 在线日韩日本国产亚洲| 免费AV片在线观看网址| 国产精品一区二区三区麻豆| 在线视频中文字幕二区| 欧美成本人视频免费播放| 不卡视频在线一区二区三区| 日韩精品一区二区三区激情视频 | 久久精品国产亚洲精品| 重口SM一区二区三区视频| 国产熟女肥臀精品国产馆乱| 国内精品久久久久影院日本| 乱码精品一区二区亚洲区| 十八禁午夜福利免费网站| 喀什市| 亚洲精品无码高潮喷水A| 在线亚洲妇色中文色综合| 国产成人精彩在线视频| 亚洲国产高清av网站| 爽爽精品dvd蜜桃成熟时电影院|