更新
This commit is contained in:
50
WPFDark/Internals/SharedResourceDictionary.cs
Normal file
50
WPFDark/Internals/SharedResourceDictionary.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user