0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Xamarin.Forms用のPrismでRegionを設定する方法(エラーを回避する方法)

Posted at

はじめに

Xamarin.Forms用のPrismでRegionを設定する方法について解説します。
(検索するといくつか解説記事がヒットするのですが、そのままでは使えなかったです。。。)

WPF用のPrismなどは以前からRegionが使えたのですが、Xamarin.Forms用のPrismは8.0から使えるようになったようです。

Prism Releases

Prism 8.0 RTM
NEW FEATURE - Region support for Prism.Forms is HERE!!!

参考にしたページ

環境

  • Prism.Forms.Regions : 8.1.97
  • Xamarin.Forms : 5.0.0.2083
  • Prism.Unity.Forms : 8.1.97

結論

参考にしたページのようにRegionを指定することを考えます。

prism:RegionManager.RegionName="ContentRegion"

この場合、Xaml内の名前空間の指定を以下のように変更する必要があります。

(変更前)

xmlns:prism="http://prismlibrary.com"

(変更後)

xmlns:prism="clr-namespace:Prism.Regions.Xaml;assembly=Prism.Forms.Regions"

※実際には以下のように分けた方がが良いと思います。

xmlns:prism="http://prismlibrary.com"
xmlns:region="clr-namespace:Prism.Regions.Xaml;assembly=Prism.Forms.Regions"

region:RegionManager.RegionName="ContentRegion"

発生していたエラー

Error XFC0000: Cannot resolve type "RegionManager". (XFC0000) (AppName) XamlC

原因

エラーに書かれている通り、RegionManagerが見つからないことが原因です。

RegionManagerを見つけるには、適切な名前空間を使えるようにする必要があると思い、RegionManagerを適当な箇所でインスタンス化して見ると以下のような表示が見えました。
image.png

上図より、RegionManagerPrism.Regions.Xaml名前空間内にいることが判明したのであとはこの名前空間が使えるようにXaml内に記載してあげればOKです。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?