WPF - XAML File Location

WPF - XAML File Location

josh.roth.MEI
Enthusiast Enthusiast
1,635 Views
4 Replies
Message 1 of 5

WPF - XAML File Location

josh.roth.MEI
Enthusiast
Enthusiast

I am working on transitioning some windows in my add-in from WinForms to WPF.

 

Can anyone help me understand where the .xaml files should be relative to my add-in DLL file in order for the Pack URI in InitializeComponent() of "assemblyname;component/forms/window.xaml" to be able to find it?

 

It works fine in debug mode with Add-In manager (since the files are in the structure that Visual Studio puts them by default), but once I move the files to the .bundle folder, I can't get it to work.

 

Many thanks!

0 Likes
Accepted solutions (1)
1,636 Views
4 Replies
Replies (4)
Message 2 of 5

RPTHOMAS108
Mentor
Mentor

The xaml should be compiled into assembly resources i.e. leave it alone and it should work by default (so what error are you getting?). You should not need to be doing loose xaml i.e. loading the xaml at run time from separate file outside of assembly.

 

Occasionally you get issues with other resources such as images because the pack uri is relative to the application and not your own assembly file. However issues with xaml is a new one for me since such resource relationships are set up by the designer when you add a window.

 

 

Message 3 of 5

josh.roth.MEI
Enthusiast
Enthusiast

Thanks for the reply! That makes a lot of sense - I'm definitely glad to hear that it should be included in the assembly and doesn't need to be located separately. Here's the error I've been getting when I try to run the command that brings up the Window (Proficient is the add-in name):

 

Screenshot_1.png

Again, it's working fine in debug with Add-In Manager, so I'm confused what is causing this exception to be thrown. Could it possibly be the build action? Right now I have it set to "Page."

0 Likes
Message 4 of 5

RPTHOMAS108
Mentor
Mentor

Are you calling the window from a different assembly from the one where the IExternalCommand is implemented? Which code language are you writing in?

 

'Page' is the right build action. In xaml x:Class should equal the class name of the code behind class. Not sure what else could be wrong.

 

How the Runtime Locates Assemblies | Microsoft Docs

 

 

 

0 Likes
Message 5 of 5

josh.roth.MEI
Enthusiast
Enthusiast
Accepted solution

You're pretty much on the right track. I figured it out this morning. The answer is less than exciting:

 

I had my AssemblyCulture set to "en-US," but didn't set the CurrentThread.CurrentCulture to "en-US" before calling ShowDialog() on the window. So it was looking for an assembly with AssemblyCulture set to "neutral" and wasn't finding it.

 

Thanks again for your help! Wish that could have been a more interesting answer. 😑

0 Likes