Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: How to start from a window in a different assembly

Tags:

I googled this and still can't get it working

I have a WPF app and want to start from Main.xaml which is located in a different assembly. Both assemblies are in the same location.

How can I do this? I took out the StartupUri from the XAML and tried with these and some slight variations:

    protected override void OnStartup(StartupEventArgs e)     {         base.OnStartup(e);          StartupUri = new Uri("/CompanyName.VisualStudio.UI;CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml", UriKind.Relative);         //StartupUri = new Uri(@"pack://application:,,,/ CompanyName.VisualStudio.UI;CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml");      } 

The name of the assembly is "CompanyName.VisualStudio.UI" and the namespace is "CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml"

Any ideas?

like image 485
Bob Avatar asked Nov 24 '10 15:11

Bob


People also ask

How do I navigate to another window in WPF?

NavigationService is for browser navigation within WPF. What you are trying to do is change to a different window TrainingFrm . To go to a different window, you should do this: private void conditioningBtn_Click(object sender, RoutedEventArgs e) { var newForm = new TrainingFrm(); //create your new form.

Is WPF phased out?

It may indeed get phased out eventually “The WPF's goal in user interface and graphics rendering in the . NET Framework 3.0 release is to provide a windowing system for the desktop environment on Microsoft Windows.

Is WPF still relevant 2021?

WPF is still one of the most used app frameworks in use on Windows (right behind WinForms).

What is the difference between a page and a window in WPF when you are adding a new file in the Solution Explorer?

Window is the root control that must be used to hold/host other controls (e.g. Button) as container. Page is a control which can be hosted in other container controls like NavigationWindow or Frame. Page control has its own goal to serve like other controls (e.g. Button). Page is to create browser like applications.


1 Answers

This article gives a clean XAML-only solution.

StartupUri="pack://application:,,,/assembly_name;component/path/file_name.xaml" 

Where:

  • assembly_name is the name of the referenced assembly, sans extension
  • path is the subfolder in which the component resides; if the component is at the project root, this element is omitted
  • file_name is the file name of the component

Examples:

pack://application:,,,/UI;component/CalculatorView.xaml assembly - UI.dll path - none (file at project root) file_name - CalculatorView  pack://application:,,,/MyApp.UI;component/Views/CalculatorView.xaml assembly - MyApp.UI.dll path - Views file_name - CalculatorView  pack://application:,,,/UI;component/Views/External/CalculatorView.xaml assembly - UI.dll path - Views/External file_name - CalculatorView  
like image 123
angularsen Avatar answered Sep 19 '22 17:09

angularsen