Пример #1
0
        public Maybe<ResourceDictionary> GetDictionary(string path)
        {
            if (!UriParser.IsKnownScheme("pack"))
                UriParser.Register(new GenericUriParser(GenericUriParserOptions.GenericAuthority), "pack", -1);

            if (!GetResourceNames().Any(s => s.Equals(path, StringComparison.InvariantCultureIgnoreCase)))
            {
                Debug.WriteLine("Unknown resource name " + path);
                return Maybe<ResourceDictionary>.None;
            }
            try
            {
                var dict = new ResourceDictionary();
                var uri = new Uri("/" + _assembly.GetName().Name + ";component/" + path.ToLowerInvariant(),
                                  UriKind.Relative);
                dict.Source = uri;
                return dict.ToMaybe();
            }
            catch (InvalidOperationException)
            {
                Debug.WriteLine(path + " could not be loaded as Resource");
                return Maybe<ResourceDictionary>.None;
            }
        }