AmazonScrape.ResourceLoader.GetControlStyle C# (CSharp) Method

GetControlStyle() public static method

Dynamically load a control style.
public static GetControlStyle ( string styleName ) : System.Windows.Style
styleName string
return System.Windows.Style
        public static Style GetControlStyle(string styleName)
        {
            if (!UriParser.IsKnownScheme("pack"))
                UriParser.Register(new GenericUriParser(GenericUriParserOptions.GenericAuthority), "pack", -1);

            ResourceDictionary dict = new ResourceDictionary();
            Uri uri = new Uri("/UI/Resources/ControlStyles.xaml", UriKind.Relative);
            dict.Source = uri;
            Application.Current.Resources.MergedDictionaries.Add(dict);

            Style style;
            try
            {
                style = (Style)Application.Current.Resources[styleName];
            }
            catch
            {
                throw new ResourceReferenceKeyNotFoundException("Can't find the Style " + styleName, styleName);
            }

            return style;
        }

Usage Example

Example #1
0
        public void AddButtonColumn(string buttonText, int widthPercent, RoutedEventHandler clickHandler, Style style = null)
        {
            FrameworkElementFactory ef = new FrameworkElementFactory(typeof(Button));

            ef.SetValue(Button.StyleProperty, ResourceLoader.GetControlStyle("ButtonStyle"));
            ef.SetValue(Button.ContentProperty, buttonText);
            ef.AddHandler(Button.ClickEvent, clickHandler, true);
            AddColumn(ef, widthPercent, "", "", style);
        }
All Usage Examples Of AmazonScrape.ResourceLoader::GetControlStyle