blairacuda
Technical User
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:
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.
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.