Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with migrating wpf control from exectuable to assembly

Status
Not open for further replies.

blairacuda

Technical User
Sep 3, 2009
51
0
0
US
short background: we are migrating from vb6 to c#/wpf. there are pieces we were simply launching via an executable from the vb6 application. the desire now is to move those controls into a library.

this migration is causing a headache when it comes to accessing the resource tree. previously we had resource dictionaries defined in our App.xaml. this worked well and allowed them to trickle down to all controls. and in certain controls where we are building pieces on the fly we were able to call Application.FindResource to get the specific piece we needed. the lack of Application.FindResource is the crux of my current insanity. i have played with a handful of options. the latest of which is:
Code:
        public object GetResourceFromAssembly(string resourceName)
        {
            var assembly = GetType().Assembly;
            string[] resources = assembly.GetManifestResourceNames();
            foreach (string resource in resources)
            {
                try
                {
                    var resourceManager = new ResourceManager(resource, assembly);
                    var res = resourceManager.GetObject(resourceName);
                    if (res != null)
                        return res;
                }
                catch (ArgumentNullException ex)
                {
                    Console.WriteLine("ArgumentNullException");
                }
                catch (MissingManifestResourceException  ex)
                {
                    Console.WriteLine("MissingManifestResourceException");
                }
                catch (Exception ex)
                {
                    Logger.LogError(ErrorCode.Unexpected_error, "", ex);
                }
            }

            return null;
        }

no matter what i do i seem to hit the MissingManifestResourceException when using resourceManager.GetObject. the particular resource i am trying to get to is my generic.xaml. it is located in a folder in the project called themes and is set to be an embedded resource for its build action. we have a handful of styles specified in generic.xaml. in today's case i am trying to get a brush out of it. this brush property is databound to a wpf button.

in short, what is the best equivalent to Application.FindResource when loading from an assembly resource. oh and the resource is not in a satellite assembly; it is compiled into the assembly trying to access it.

CBlair
Crystal, InstallShield, branching out in other programming realms.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top