本文整理汇总了C#中System.Windows.FrameworkElement.TryFindResource方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.TryFindResource方法的具体用法?C# FrameworkElement.TryFindResource怎么用?C# FrameworkElement.TryFindResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.TryFindResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryFindDataTemplate
private static DataTemplate TryFindDataTemplate(FrameworkElement element, object dataTemplateKey)
{
object dataTemplate = element.TryFindResource(dataTemplateKey);
if (dataTemplate == null)
{
dataTemplateKey = new ComponentResourceKey(typeof(PropertyGrid), dataTemplateKey);
dataTemplate = element.TryFindResource(dataTemplateKey);
}
return dataTemplate as DataTemplate;
}
示例2: TryFindDataTemplate
private static DataTemplate TryFindDataTemplate(FrameworkElement element, object dataTemplateKey)
{
if (dataTemplateKey.ToString().Contains("Task"))
{
// Todo: remove me after testing.
}
object dataTemplate = element.TryFindResource(dataTemplateKey);
if (dataTemplate == null)
{
dataTemplateKey = new ComponentResourceKey(typeof(PropertyGrid), dataTemplateKey);
dataTemplate = element.TryFindResource(dataTemplateKey);
}
return dataTemplate as DataTemplate;
}
示例3: ClientInformation
public ClientInformation()
{
InitializeComponent();
try
{
frameworkElement = new FrameworkElement();
textBoxNormalStyle = (Style)frameworkElement.TryFindResource("textBoxNormalStyle");
textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxErrorStyle");
}
catch (Exception ex)
{
Helper.LogException(ex);
}
}
示例4: FindDataTemplate
/// <summary>
/// Find a DataTemplate for the specified type in the visual-tree.
/// </summary>
public static DataTemplate FindDataTemplate(Type type, FrameworkElement element)
{
var dataTemplate = element.TryFindResource(new DataTemplateKey(type)) as DataTemplate;
if (dataTemplate != null)
{
return dataTemplate;
}
if (type.BaseType != null && type.BaseType != typeof(object))
{
dataTemplate = FindDataTemplate(type.BaseType, element);
if (dataTemplate != null)
{
return dataTemplate;
}
}
foreach (var interfaceType in type.GetInterfaces())
{
dataTemplate = FindDataTemplate(interfaceType, element);
if (dataTemplate != null)
{
return dataTemplate;
}
}
return null;
}
示例5: IsNumberOnly
internal static bool IsNumberOnly(TextBox input)
{
bool result = false;
try
{
if (Regex.IsMatch(input.Text, @"^\d+$"))
{
SetToDefaultStyle(input);
result = true;
}
else
{
Style textBoxErrorStyle;
FrameworkElement frameworkElement;
frameworkElement = new FrameworkElement();
//textBoxNormalStyle = (Style)frameworkElement.TryFindResource("textBoxNormalStyle");
textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxNumericErrorStyle");
input.Style = textBoxErrorStyle;
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
return result;
}
示例6: IsNonEmpty
internal static bool IsNonEmpty(TextBox input)
{
bool result = false;
try
{
if (false == string.IsNullOrEmpty(input.Text))
{
SetToDefaultStyle(input);
result = true;
}
else
{
Style textBoxErrorStyle;
FrameworkElement frameworkElement;
frameworkElement = new FrameworkElement();
textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxEmptyErrorStyle");
input.Style = textBoxErrorStyle;
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
return result;
}
示例7: ResourceItem
public ResourceItem(object resourceKey, ResourceDictionary dictionary, FrameworkElement source, ResourceScope resourceScope)
{
_resourceKey = resourceKey;
_resourceScope = resourceScope;
_dictionary = dictionary;
_value = dictionary[resourceKey];
if( _value == null)
{
_value = source.TryFindResource(resourceKey);
}
}
示例8: CreateResourceItem
/// <summary>
/// Creates a best matching resource item for the provided resource
/// </summary>
public static ResourceItem CreateResourceItem(object resourceKey, ResourceDictionary dictionary, FrameworkElement source, ResourceScope scope)
{
var resource = dictionary[resourceKey] ?? source.TryFindResource(resourceKey);
if (resource is Style) return new StyleResourceItem(resourceKey, dictionary, source, scope);
if (resource is Brush) return new BrushResourceItem(resourceKey, dictionary, source, scope);
if (resource is Drawing) return new DrawingResourceItem(resourceKey, dictionary, source, scope);
if (resource is Color) return new ColorResourceItem(resourceKey, dictionary, source, scope);
if (resource is Geometry) return new GeometryResourceItem(resourceKey, dictionary, source, scope);
return new ResourceItem(resourceKey, dictionary, source, scope);
}
示例9: FindResource
protected virtual DataTemplate FindResource(FrameworkElement container, string key)
{
return container.TryFindResource(key) as DataTemplate;
}
示例10: SetToDefaultStyle
private static void SetToDefaultStyle(TextBox input)
{
try
{
Style txtNormalStyle;
FrameworkElement frameworkElement;
frameworkElement = new FrameworkElement();
txtNormalStyle = (Style)frameworkElement.TryFindResource("DefaultTextBox");
input.Style = txtNormalStyle;
}
catch (Exception ex)
{
Logger.LogException(ex);
}
}
示例11: IsValidPhone
internal static bool IsValidPhone(TextBox input)
{
bool result = false;
try
{
if (input.Text == string.Empty)
{
SetToDefaultStyle(input);
return true;
}
if (Regex.IsMatch(input.Text, @"^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$"))
//if (Regex.IsMatch(input.Text, @"/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/"))
{
SetToDefaultStyle(input);
result = true;
}
else
{
Style textBoxErrorStyle;
FrameworkElement frameworkElement;
frameworkElement = new FrameworkElement();
textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxPhoneErrorStyle");
input.Style = textBoxErrorStyle;
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
return result;
}
示例12: IsValidEmail
internal static bool IsValidEmail(TextBox input)
{
bool result = false;
try
{
if (input.Text == string.Empty)
{
SetToDefaultStyle(input);
return true;
}
if (Regex.IsMatch(input.Text, @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"))
{
SetToDefaultStyle(input);
result = true;
}
else
{
Style textBoxErrorStyle;
FrameworkElement frameworkElement;
frameworkElement = new FrameworkElement();
textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxEmailErrorStyle");
input.Style = textBoxErrorStyle;
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
return result;
}
示例13: TryCreateBinding
private static Binding TryCreateBinding(FrameworkElement e, string resourceName)
{
var resource = e.TryFindResource(resourceName);
if (resource != null)
return new Binding { Source = resource, IsAsync = true };
return null;
}
示例14: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is BaloonMode)) return null;
var mode = (BaloonMode)value;
var fe = new FrameworkElement();
switch (mode)
{
case BaloonMode.FirstRun:
return fe.TryFindResource("thumbs_up") as BitmapImage;
//return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "thumbs_up.png"));
case BaloonMode.NewVersion:
case BaloonMode.CriticalUpdates:
return fe.TryFindResource("package_new") as BitmapImage;
//return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "package_new.png"));
case BaloonMode.NoteSent:
return fe.TryFindResource("outbox_out") as BitmapImage;
//return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "outbox_out.png"));
case BaloonMode.NoteReceived:
return fe.TryFindResource("inbox_into") as BitmapImage;
//return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "inbox_into.png"));
case BaloonMode.Error:
return fe.TryFindResource("error") as BitmapImage;
//return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "error.png"));
case BaloonMode.Information:
return fe.TryFindResource("information") as BitmapImage;
//return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "information.png"));
default:
return null;
}
}
示例15: IsValidCurrency
internal static bool IsValidCurrency(TextBox input)
{
bool result = false;
try
{
if (input.Text == "0.00")
{
SetToDefaultStyle(input);
return true;
}
if (false == string.IsNullOrEmpty(input.Text) && Regex.IsMatch(input.Text, @"^[0-9]*(?:\.[0-9]*)?$"))
{
SetToDefaultStyle(input);
result = true;
}
else
{
Style textBoxErrorStyle;
FrameworkElement frameworkElement;
frameworkElement = new FrameworkElement();
textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxCurrencyErrorStyle");
input.Style = textBoxErrorStyle;
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
return result;
}