Icons from other projects not showing up in Pro Add-In Dialog

105
5
Jump to solution
09-18-2019 02:34 PM
Highlighted
New Contributor III

We're building an Add-In (C#) whose buttons open up quite a few different dialogs. Some of these dialogs are instantiated directly from a view in the Add-In project, and others are instantiated from views that exist in other referenced projects. The icons in question all exist within a different project.

No matter the specific case, these icons are not showing up in the dialogs opened within the Add-In. Even so, they DO show up in the XAML editor. The only way we've been able to get icons to show up is to place them directly into an Images folder within the Add-In's project. This is fine in a couple of cases, but in general it doesn't work because we're using Dialogs that exist in our common / core set of projects. These dialogs and their respective icons work just fine in every other WPF application.

Is there some way around this issue, other than pulling all of those dialogs and their respective images into our Add-In's project's code? We're using the typical Source="pack://application:,,,/Assembly;component/path" referencing scheme in the Source attribute of the Image element in the XAML of these dialogs.

Tags (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Regular Contributor

Hi David,

I see this problem now too. Upon investigation - Images referenced using the Pack URI will display only when the dll is loaded and in memory. In this case, the dll is not loaded and hence the resource dictionary that Pro has in memory does not contain your image.  There are 2 ways (probably more) to get this to work -

1. Create a class in your resource dll that you instantiate in your add-in's module class. This will load the resource dll when the add-in is loaded, which will allow the image to be displayed.

2. In your module class's initialize override, load the resource assembly using the code snippet below.  

// In Add-in's module class:

protected override bool Initialize()
{
Load();
return base.Initialize();
}
private void Load()
{
string assemblyName = "ResourceDllWithUserControl";
string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string assemblyPath = Path.Combine(folderPath, string.Format("{0}.dll", new AssemblyName(assemblyName).Name));
Assembly assembly = Assembly.LoadFrom(assemblyPath);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks

Uma

View solution in original post

5 Replies
Highlighted
Esri Regular Contributor

Hi David,

When Pro load's your add-ins (which have references to images in other dlls) - Pro needs to know where these dlls are.  Here are two scenarios:

1. If the referenced dll with the images is another add-in, you could set that add-in's autoload attribute (located in the config.daml) to true.  This way, when your add-in loads, the add-in with the images will also load, thus resolving the image source uris.

2. If the referenced dll with the images is a resource dll (not an add-in), then when you reference it from your add-in, set its "Copy Local" attribute to true. So when your add-in loads, the dll with the images will also be extracted to Pro's assembly Cache, thus resolving the image source uris at runtime.

Thanks

Uma

Highlighted
New Contributor III

Thanks for responding, Uma. Unfortunately, I'm still stuck on this issue.

This is a case of situation #2 - I am referencing an image in a resource DLL. To be more specific, the Add-In project uses a view defined in a referenced DLL, which itself refers to another resource DLL that contains the icons. Copy Local is set to true in both instances. If I go to the ArcGIS Pro App Cache, I can see both of these DLLs there (the one that defines the view and the one with the icons).

This scheme works as expected in our other applications that use the same view and icon. For some reason, it's just not working with an ArcGIS Pro add-in. Any other advice?

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi David,

I see this problem now too. Upon investigation - Images referenced using the Pack URI will display only when the dll is loaded and in memory. In this case, the dll is not loaded and hence the resource dictionary that Pro has in memory does not contain your image.  There are 2 ways (probably more) to get this to work -

1. Create a class in your resource dll that you instantiate in your add-in's module class. This will load the resource dll when the add-in is loaded, which will allow the image to be displayed.

2. In your module class's initialize override, load the resource assembly using the code snippet below.  

// In Add-in's module class:

protected override bool Initialize()
{
Load();
return base.Initialize();
}
private void Load()
{
string assemblyName = "ResourceDllWithUserControl";
string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string assemblyPath = Path.Combine(folderPath, string.Format("{0}.dll", new AssemblyName(assemblyName).Name));
Assembly assembly = Assembly.LoadFrom(assemblyPath);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks

Uma

View solution in original post

Highlighted
New Contributor III

Thanks! I tried the second solution, and it worked.

-David

Reply
0 Kudos
Highlighted
New Contributor III

I had some luck with this format. Not sure what to put in for the public key but a single p seems to work (so did other letters). This is assuming your referenced dll has a version of 1.0.0.0 and no public key.

      <Image Source="/ResourceDLL;v1.0.0.0;p;component/MyImages/BexDog32.png"/>

Reply
0 Kudos