本文整理汇总了C#中System.Windows.ResourceDictionary.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceDictionary.Remove方法的具体用法?C# ResourceDictionary.Remove怎么用?C# ResourceDictionary.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.ResourceDictionary
的用法示例。
在下文中一共展示了ResourceDictionary.Remove方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyResourceDictionary
private static void ApplyResourceDictionary(ResourceDictionary newRd, ResourceDictionary oldRd)
{
foreach (DictionaryEntry r in newRd)
{
if (oldRd.Contains(r.Key))
oldRd.Remove(r.Key);
oldRd.Add(r.Key, r.Value);
}
}
示例2: ChangeTheme
private static void ChangeTheme(ResourceDictionary resources, Tuple<Theme, Accent> oldThemeInfo, Accent accent, Theme newTheme)
{
if (oldThemeInfo != null)
{
var oldAccent = oldThemeInfo.Item2;
if (oldAccent != null && oldAccent.Name != accent.Name)
{
var accentResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldAccent.Resources.Source);
if (accentResource != null) {
var ok = resources.MergedDictionaries.Remove(accentResource);
// really need this???
foreach (DictionaryEntry r in accentResource)
{
if (resources.Contains(r.Key))
resources.Remove(r.Key);
}
resources.MergedDictionaries.Add(accent.Resources);
}
}
var oldTheme = oldThemeInfo.Item1;
if (oldTheme != null && oldTheme != newTheme)
{
var oldThemeResource = (oldTheme == Theme.Light) ? LightResource : DarkResource;
var md = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldThemeResource.Source);
if (md != null)
{
var ok = resources.MergedDictionaries.Remove(md);
var newThemeResource = (newTheme == Theme.Light) ? LightResource : DarkResource;
// really need this???
foreach (DictionaryEntry r in oldThemeResource)
{
if (resources.Contains(r.Key))
resources.Remove(r.Key);
}
resources.MergedDictionaries.Add(newThemeResource);
}
}
}
else
{
ChangeTheme(resources, accent, newTheme);
}
}
示例3: SetThemeSource
private void SetThemeSource(Uri source, bool useThemeAccentColor)
{
if (source == null) {
throw new ArgumentNullException("source");
}
var oldThemeDict = GetThemeDictionary();
var dictionaries = Application.Current.Resources.MergedDictionaries;
var themeDict = new ResourceDictionary { Source = source };
// if theme defines an accent color, use it
var accentColor = themeDict[KeyAccentColor] as Color?;
if (accentColor.HasValue) {
// remove from the theme dictionary and apply globally if useThemeAccentColor is true
themeDict.Remove(KeyAccentColor);
if (useThemeAccentColor) {
ApplyAccentColor(accentColor.Value);
}
}
// add new before removing old theme to avoid dynamicresource not found warnings
dictionaries.Add(themeDict);
// remove old theme
if (oldThemeDict != null) {
dictionaries.Remove(oldThemeDict);
}
OnPropertyChanged("ThemeSource");
}
示例4: MergedDictionaries_KeyClashes
public void MergedDictionaries_KeyClashes ()
{
var key = "Key";
var value = new object ();
var value1 = new object ();
var value2 = new object ();
var merge1 = new ResourceDictionary ();
var merge2 = new ResourceDictionary ();
ResourceDictionary main = new ResourceDictionary ();
main.MergedDictionaries.Add (merge1);
main.MergedDictionaries.Add (merge2);
main.Add (key, value);
merge1.Add (key, value1);
merge2.Add (key, value2);
// We ignore the values in the merged dictionaries if the main dictionary
// has the key
Assert.AreEqual (value, main [key], "#1");
main.Remove (key);
// We should look up the merged dictionaries in reverse order
Assert.AreEqual (value2,main [key], "#2");
merge2.Remove (key);
// Now we should find it in the first merged dictionary
Assert.AreEqual (value1, main [key], "#3");
}
示例5: Contains_TypeAndStringInResourceDictionary_TypeFirst
public void Contains_TypeAndStringInResourceDictionary_TypeFirst()
{
var rd = new ResourceDictionary();
rd.Add(typeof(Button), new Style { TargetType = typeof(Button) });
rd.Add("System.Windows.Controls.Button", "System.Windows.Controls.Button");
Assert.IsTrue(rd.Contains(typeof(Button)), "#1");
Assert.IsTrue(rd.Contains("System.Windows.Controls.Button"), "#2");
rd.Remove(typeof(Button));
Assert.IsFalse(rd.Contains(typeof(Button)), "#3");
Assert.IsTrue(rd.Contains("System.Windows.Controls.Button"), "#4");
}
示例6: LoadResources
private void LoadResources(string[] uriStrings)
{
foreach (string uri in uriStrings)
{
ResourceDictionary resources = new ResourceDictionary();
resources.Source = new Uri(uri, UriKind.Relative);
foreach (object key in resources.Keys)
{
object value = resources[key];
resources.Remove(key);
this.Resources.Add(key, value);
}
}
}
示例7: SetThemeSource
static void SetThemeSource(Uri source)
{
var oldThemeDict = GetThemeDictionary();
var dictionaries = Application.Current.Resources.MergedDictionaries;
var themeDict = new ResourceDictionary { Source = source };
// if theme defines an accent color, use it
var accentColor = themeDict[KeyAccentColor] as Color?;
if (accentColor.HasValue)
// remove from the theme dictionary and apply globally if useThemeAccentColor is true
themeDict.Remove(KeyAccentColor);
// add new before removing old theme to avoid dynamicresource not found warnings
dictionaries.Add(themeDict);
// remove old theme
if (oldThemeDict != null) dictionaries.Remove(oldThemeDict);
}