当前位置: 首页>>代码示例>>C#>>正文


C# FrameworkElement.TryFindResource方法代码示例

本文整理汇总了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;
 }
开发者ID:andyhebear,项目名称:likeleon,代码行数:10,代码来源:PropertyTemplateSelector.cs

示例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;
 }
开发者ID:Jedzia,项目名称:BackBock,代码行数:14,代码来源:PropertyTemplateSelector.cs

示例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);
            }
        }
开发者ID:ultrasonicsoft,项目名称:css,代码行数:15,代码来源:ClientInformation.xaml.cs

示例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;
        }
开发者ID:minikie,项目名称:OTCDerivativesCalculatorModule,代码行数:31,代码来源:DataTemplateUtils.cs

示例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;
        }
开发者ID:ultrasonicsoft,项目名称:G1,代码行数:27,代码来源:Helper.cs

示例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;
        }
开发者ID:ultrasonicsoft,项目名称:G1,代码行数:27,代码来源:Helper.cs

示例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);
     }
 }
开发者ID:bdurrani,项目名称:WPF-Inspector,代码行数:11,代码来源:ResourceItem.cs

示例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);
        }
开发者ID:bdurrani,项目名称:WPF-Inspector,代码行数:15,代码来源:ResourceItemFactory.cs

示例9: FindResource

 protected virtual DataTemplate FindResource(FrameworkElement container, string key)
 {
     return container.TryFindResource(key) as DataTemplate;
 }
开发者ID:Zvirja,项目名称:TrayGarden,代码行数:4,代码来源:ServiceForPlantDataTemplateSelector.cs

示例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);
     }
 }
开发者ID:ultrasonicsoft,项目名称:G1,代码行数:15,代码来源:Helper.cs

示例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;
        }
开发者ID:ultrasonicsoft,项目名称:G1,代码行数:32,代码来源:Helper.cs

示例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;
        }
开发者ID:ultrasonicsoft,项目名称:G1,代码行数:32,代码来源:Helper.cs

示例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;
 }
开发者ID:neoeinstein,项目名称:xpdm.Catan,代码行数:7,代码来源:Tile.xaml.cs

示例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;
     }
 }
开发者ID:hyrmedia,项目名称:PNotes.NET,代码行数:30,代码来源:PNConverters.cs

示例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;
        }
开发者ID:ultrasonicsoft,项目名称:G1,代码行数:33,代码来源:Helper.cs


注:本文中的System.Windows.FrameworkElement.TryFindResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。