2010-11-24 56 views
21

我GOOGLE了這一點,仍然無法得到它的工作WPF:如何從一個窗口開始在不同的裝配

我有一個WPF應用程序,並想從Main.xaml它位於不同的裝配開始。兩個組件都在相同的位置。

我該怎麼做?我從XAML拿出的StartupUri並與這些和一些細微變化的嘗試:

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"); 

    } 

的組件的名稱是「CompanyName.VisualStudio.UI」而命名爲「公司名稱/ VisualStudio中/ UI /的DatabaseManager/Main.xaml「

任何想法?

+1

我這樣讀爲「WTF:...」;-) – Orbling 2010-11-24 15:31:30

回答

3

我會檢查你的包的URI。下面是我試試的uri。將'component'視爲項目中的根文件夾,並將'FolderName'放在適當的文件夾名稱中,或者如果Main.xaml位於項目的根目錄中,請將其刪除。

StartupUri = new Uri(@"pack://application:,,,/CompanyName.VisualStudio.UI;component/FolderName/Main.xaml", UriKind.Absolute);

34

This article給人一種乾淨僅XAML的解決方案。

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

其中:

  • assembly_name是所引用的組件的名稱,擴展SANS
  • 路徑是將組件所在的子文件夾;如果組件在項目的根,這個元素被省略
  • file_name是組件的文件名

例子:

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 
1

老問題,但this也很有幫助:

void App_Startup(object sender, StartupEventArgs e) 
     { 
      MainWindow = new YourWindow(some, arguments); 
      MainWindow.Show(); 
} 

和我的App.xaml:

<Application 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Class="SDKSample.App" 
    Startup="App_Startup" /> 

並記住ShutdownMode:如果你還記得在關閉最後一個之前打開新窗口,你應該是不錯的

相關問題