グーグルで調べたけどまだ動かない
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」で、名前空間は「CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml」です。
何か案は?
ベストアンサー1
この記事クリーンな XAML のみのソリューションを提供します。
StartupUri="pack://application:,,,/assembly_name;component/path/file_name.xaml"
どこ:
- assembly_nameは参照アセンブリの名前(拡張子なし)です。
- パスはコンポーネントが存在するサブフォルダです。コンポーネントがプロジェクトルートにある場合、この要素は省略されます。
- 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