This commit is contained in:
ShrlAlgo
2025-07-11 09:20:23 +08:00
parent c7b104f44f
commit 4d35cadb56
840 changed files with 102347 additions and 11595 deletions

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
namespace WPFDark.Internals
{
public class SharedResourceDictionary : ResourceDictionary
{
private static readonly Dictionary<int, ResourceDictionary> _sharedDictionaries = new Dictionary<int, ResourceDictionary>();
private static readonly bool _isInDesignerMode;
private Uri? _sourceUri;
static SharedResourceDictionary()
{
_isInDesignerMode = (bool) DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue;
}
public new Uri Source
{
get => _sourceUri ?? throw new NullReferenceException();
set
{
_sourceUri = value;
if (_isInDesignerMode)
{
base.Source = value;
return;
}
var hashCode = value.GetHashCode();
if (_sharedDictionaries.TryGetValue(hashCode, out var v) == false)
{
base.Source = value;
_sharedDictionaries.Add(hashCode, this);
}
else
{
MergedDictionaries.Add(v);
}
}
}
}
}