示例#1
0
        /// <summary>
        /// Fills the cache when called for the first times. Does nothing on subsequent calls.
        /// </summary>
        private void Initialize()
        {
            if (InitResourceSource == typeof(object))
            {
                AssemblyName InitAssemblyName = new AssemblyName(AssemblyName);
                InitResourceAssembly = Assembly.Load(InitAssemblyName);

                string[] ResourceNames = InitResourceAssembly.GetManifestResourceNames();

                foreach (string ResourceName in ResourceNames)
                {
                    if (ResourceName.EndsWith(ResourceExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        Type?ResourceType = InitResourceAssembly.GetType(ResourceName.Substring(0, ResourceName.Length - ResourceExtension.Length));
                        if (ResourceType != null)
                        {
                            InitResourceSource = ResourceType;
                            break;
                        }
                    }
                }

                InitResourceManager = new ResourceManager(InitResourceSource);
            }
        }
示例#2
0
        /// <summary>
        /// Gets a localized image source from the assembly by its resource name.
        /// </summary>
        /// <param name="name">The resource name.</param>
        /// <returns>The localized image.</returns>
        public ImageSource GetImageSource(string name)
        {
            Initialize();

            string AssemblyName = InitResourceAssembly.GetName().Name !;
            string UriPath      = "pack://application:,,,/" + AssemblyName + ";component/" + IconPath + name;

            try
            {
                BitmapImage ImageResource = new BitmapImage(new Uri(UriPath));
                return(ImageResource);
            }
            catch (IOException)
            {
                throw new ArgumentOutOfRangeException(nameof(name));
            }
        }