本文整理汇总了C#中System.Windows.ResourceDictionary.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceDictionary.Contains方法的具体用法?C# ResourceDictionary.Contains怎么用?C# ResourceDictionary.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.ResourceDictionary
的用法示例。
在下文中一共展示了ResourceDictionary.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecurseDictionaries
static object RecurseDictionaries(ResourceDictionary dictionary, string name)
{
if (dictionary.Contains(name)) return dictionary[name];
return dictionary.MergedDictionaries
.Select(child => RecurseDictionaries(child, name))
.FirstOrDefault(candidate => candidate != null);
}
示例2: ChangeRd
private void ChangeRd(ResourceDictionary rd, string newKey, object newValue)
{
if (!rd.Contains(newKey))
{
rd.Add(newKey, newValue);
SaveChange();
}
}
示例3: AdjustResourceColor
private static void AdjustResourceColor(ResourceDictionary resources, string sourceKey, string targetKey, float factor)
{
if (!resources.Contains(sourceKey))
return;
var sourceColor = (Color)resources[sourceKey];
var targetColor = sourceColor.ToBrightened(factor);
if (resources.Contains(targetKey))
{
resources[targetKey] = targetColor;
}
else
{
resources.Add(targetKey, targetColor);
}
}
示例4: TryGetValue
private static bool TryGetValue(ResourceDictionary dict, string key, out object val)
{
val = null;
if (!dict.Contains(key))
{
return false;
}
val = dict[key];
return true;
}
示例5: 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);
}
}
示例6: TryFindDataTemplate
private static DataTemplate TryFindDataTemplate(ResourceDictionary resourceDictionary, string contentTypeName)
{
DataTemplate dataTemplate = null;
if (resourceDictionary.Contains(contentTypeName))
{
dataTemplate = resourceDictionary[contentTypeName] as DataTemplate;
}
return dataTemplate;
}
示例7: GetValueFromDictionary
private object GetValueFromDictionary(string key, ResourceDictionary dictionary)
{
if (dictionary.Contains(key))
{
return dictionary[key];
}
foreach (var resourceDictionary in dictionary.MergedDictionaries)
{
var result = GetValueFromDictionary(key, resourceDictionary);
if (result != null) return result;
}
return null;
}
示例8: GetIcon
public BitmapSource GetIcon(string pResourceName, string pModule)
{
var resourceDictionaryUri = new Uri(
string.Format("/{0};component/{1}/Images.xaml", GetType().Assembly.GetName().Name, pModule),
UriKind.RelativeOrAbsolute);
var resourceDictionary = new ResourceDictionary { Source = resourceDictionaryUri };
if (!resourceDictionary.Contains(pResourceName))
{
throw new ArgumentException(string.Format("the resource {0} could not be found on resource dictionary {1}", pResourceName, resourceDictionaryUri));
}
var resource = resourceDictionary[pResourceName];
return resource as BitmapSource;
}
示例9: 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);
}
}
示例10: Transitions
static Transitions() {
var dict = new ResourceDictionary {
Source = typeof(Transitions).Assembly.ToPackUri("Mpcr.Core.Wpf.Transitions/Primitives/TransitionStoryboards.xaml")
};
foreach (var prop in typeof(Transitions).GetStaticProperties(true, true)) {
var propKey = "@{0}".Substitute(prop.Name);
Assumption.IsTrue(dict.Contains(propKey), "Standard transition '{0}' is not defined", prop.Name);
var transition = dict[propKey] as Transition;
Assumption.IsA(transition, prop.PropertyType, "Standard transition '{0}' is not of the expected type '{1}'", prop.Name, prop.PropertyType);
if (transition is StoryboardTransition2D) {
var stb = (StoryboardTransition2D)transition;
if (stb.NewContentStyle != null) stb.NewContentStyle.Seal();
if (stb.OldContentStyle != null) stb.OldContentStyle.Seal();
}
transition.Freeze();
prop.SetValue(null, transition, null);
}
}
示例11: BeginElementStoryboard
public static void BeginElementStoryboard(ResourceDictionary resources, UIElement target, string subTargetName, string StoryboardName, PropertyPath propertyPath, EventHandler completedHandler)
{
if (!resources.Contains(StoryboardName))
{
throw new ArgumentException(string.Format("Resource with name {0} not found!", StoryboardName));
}
if (!string.IsNullOrEmpty(subTargetName))
{
target = (target as FrameworkElement).FindName(subTargetName) as UIElement;
}
Storyboard sbAlpha = resources[StoryboardName] as Storyboard;
Storyboard sb = CloneStoryboard(sbAlpha);
Storyboard.SetTarget(sb, target);
Storyboard.SetTargetProperty(sb, propertyPath);
if (completedHandler != null)
{
sb.Completed += completedHandler;
}
sb.Begin();
}
示例12: Contains_TypeAsKeyStyleWithTargetTypeSet_ReturnsTrue
public void Contains_TypeAsKeyStyleWithTargetTypeSet_ReturnsTrue ()
{
ResourceDictionary rd = new ResourceDictionary ();
Style s = new Style () {
TargetType = typeof (Button),
};
rd.Add (typeof (Button), s);
bool contains = rd.Contains (typeof (Button));
Assert.IsTrue (contains);
}
示例13: Contains_ObejctAsKey_Throws
public void Contains_ObejctAsKey_Throws ()
{
ResourceDictionary rd = new ResourceDictionary ();
Assert.Throws<ArgumentException> (() => rd.Contains (new object ()));
}
示例14: CreateStyleForwardersForDefaultStyles
/// <summary>
/// Creates style forwarders for default styles. This means that all styles found in the theme that are
/// name like Default[CONTROLNAME]Style (i.e. "DefaultButtonStyle") will be used as default style for the
/// control.
/// This method will use the passed resources.
/// </summary>
/// <param name="rootResourceDictionary">The root resource dictionary.</param>
/// <param name="sourceResources">Resource dictionary to read the keys from (thus that contains the default styles).</param>
/// <param name="targetResources">Resource dictionary where the forwarders will be written to.</param>
/// <param name="forceForwarders">if set to <c>true</c>, styles will not be completed but only forwarders are created.</param>
/// <param name="defaultPrefix">The default prefix, uses to determine the styles as base for other styles.</param>
/// <param name="recreateStylesBasedOnTheme">if set to <c>true</c>, the styles will be recreated with BasedOn on the current theme.</param>
/// <exception cref="ArgumentNullException">The <paramref name="rootResourceDictionary" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException">The <paramref name="sourceResources" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException">The <paramref name="targetResources" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">The <paramref name="defaultPrefix" /> is <c>null</c> or whitespace.</exception>
public static void CreateStyleForwardersForDefaultStyles(ResourceDictionary rootResourceDictionary, ResourceDictionary sourceResources,
ResourceDictionary targetResources, bool forceForwarders, string defaultPrefix = DefaultKeyPrefix, bool recreateStylesBasedOnTheme = false)
{
Argument.IsNotNull("rootResourceDictionary", rootResourceDictionary);
Argument.IsNotNull("sourceResources", sourceResources);
Argument.IsNotNull("targetResources", targetResources);
Argument.IsNotNullOrWhitespace("defaultPrefix", defaultPrefix);
#region If forced, use old mechanism
if (forceForwarders)
{
// Get all keys from this resource dictionary
var keys = (from key in sourceResources.Keys as ICollection<object>
where key is string &&
((string)key).StartsWith(defaultPrefix, StringComparison.Ordinal) &&
((string)key).EndsWith(DefaultKeyPostfix, StringComparison.Ordinal)
select key).ToList();
foreach (string key in keys)
{
var style = sourceResources[key] as Style;
if (style != null)
{
Type targetType = style.TargetType;
if (targetType != null)
{
try
{
#if NET
var styleForwarder = new Style(targetType, style);
#else
var styleForwarder = new Style(targetType);
styleForwarder.BasedOn = style;
#endif
targetResources.Add(targetType, styleForwarder);
}
catch (Exception ex)
{
Log.Warning(ex, "Failed to create style forwarder for '{0}'", key);
}
}
}
}
foreach (var resourceDictionary in sourceResources.MergedDictionaries)
{
CreateStyleForwardersForDefaultStyles(rootResourceDictionary, resourceDictionary, targetResources, forceForwarders, defaultPrefix);
}
return;
}
#endregion
var defaultStyles = FindDefaultStyles(sourceResources, defaultPrefix);
foreach (var defaultStyle in defaultStyles)
{
try
{
var targetType = defaultStyle.TargetType;
if (targetType != null)
{
bool hasSetStyle = false;
var resourceDictionaryDefiningStyle = FindResourceDictionaryDeclaringType(targetResources, targetType);
if (resourceDictionaryDefiningStyle != null)
{
var style = resourceDictionaryDefiningStyle[targetType] as Style;
if (style != null)
{
Log.Debug("Completing the style info for '{0}' with the additional info from the default style definition", targetType);
resourceDictionaryDefiningStyle[targetType] = CompleteStyleWithAdditionalInfo(style, defaultStyle);
hasSetStyle = true;
}
}
if (!hasSetStyle)
{
Log.Debug("Couldn't find style definition for '{0}', creating style forwarder", targetType);
#if NET
var style = new Style(targetType, defaultStyle);
if (!targetResources.Contains(targetType))
{
//.........这里部分代码省略.........
示例15: Contains_TypeAndStringInResourceDictionary_TypeSecond
public void Contains_TypeAndStringInResourceDictionary_TypeSecond()
{
var rd = new ResourceDictionary();
rd.Add("System.Windows.Controls.Button", "System.Windows.Controls.Button");
Assert.IsTrue(rd.Contains("System.Windows.Controls.Button"), "#1");
Assert.IsFalse (rd.Contains(typeof (Button)), "#2");
Assert.Throws<ArgumentException>(() => {
rd.Add(typeof(Button), new Style { TargetType = typeof(Button) });
}, "#3");
}