LoginSignup
1
0

More than 1 year has passed since last update.

App.xaml のビルドアクションを Page にすると Application.Resources が読み込まれない

Last updated at Posted at 2023-02-06

はじめに

本記事は .NET6 で検証している。

対処

App.xaml.cs で InitializeComponent メソッドを呼び出すコードを追加する。

public App()
{
  InitializeComponent();
}

どうしてこうなった

ビルドアクションを Page にするとソース ジェネレーターで InitializeComponent メソッドを自動生成する。ただ、これを呼び出す場所は自動生成しない。

InitializeComponent って何?

次のことをしている

System.Windows.Application.LoadComponent(
  this,
  new System.Uri(
    "/$safeprojectname$;component/App.xaml",
    System.UriKind.Relative
    )
  );

ビルドアクションを ApplicationDefinition 変えないと?

スタートアップ オブジェクトを App.xaml から変更すると App.xaml の自動生成をしない。よって、InitializeComponent メソッドも呼び出せなくなる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0