Xamarin.Forms 与 Prism 8 RegionManager KeyNotFoundException
Xamarin.Forms with Prism 8 RegionManager KeyNotFoundException
我在从 Prism 的部分视图支持迁移到使用区域时遇到问题。问题出现在下面的示例中。我在 Prism.Forms 8 + Xamarin.Forms 5.
的其他项目中遇到了同样的问题
https://github.com/CrossGeeks/PrismRegionsXFSample
System.Collections.Generic.KeyNotFoundException: The region manager does not contain the ContentRegion region.
at Prism.Regions.RegionCollection.get_Item (System.String regionName) [0x0000f] in /_/src/Forms/Prism.Forms.Regions/Regions/RegionCollection.cs:43
at Prism.Regions.RegionManager.RequestNavigate (System.String regionName, System.Uri target, System.Action`1[T] navigationCallback, Prism.Navigation.INavigationParameters navigationParameters) [0x00013] in /_/src/Forms/Prism.Forms.Regions/Regions/RegionManager.cs:44
at Prism.Regions.RegionManager.RequestNavigate (System.String regionName, System.Uri target, System.Action`1[T] navigationCallback) [0x00000] in /_/src/Forms/Prism.Forms.Regions/Regions/RegionManager.cs:37
at Prism.Regions.IRegionManagerExtensions.RequestNavigate (Prism.Regions.IRegionManager regionManager, System.String regionName, System.String target, System.Action`1[T] navigationCallback) [0x00024] in /_/src/Forms/Prism.Forms.Regions/Regions/IRegionManagerExtensions.cs:40
at RegionInitialize.ViewModels.MainPageViewModel.Test () [0x00001] in /Users/lestersconyers/Downloads/RegionInitialize/RegionInitialize/RegionInitialize/ViewModels/MainPageViewModel.cs:39
at Prism.Commands.DelegateCommand.Execute () [0x00000] in /_/src/Prism.Core/Commands/DelegateCommand.cs:49
at Prism.Commands.DelegateCommand.Execute (System.Object parameter) [0x00000] in /_/src/Prism.Core/Commands/DelegateCommand.cs:67
at Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.Execute (System.Object parameter) [0x00000] in /_/src/Prism.Core/Commands/DelegateCommandBase.cs:62
at Xamarin.Forms.ButtonElement.ElementClicked (Xamarin.Forms.VisualElement visualElement, Xamarin.Forms.Internals.IButtonElement ButtonElementManager) [0x00008] in D:\a\s\Xamarin.Forms.Core\ButtonElement.cs:60
at Xamarin.Forms.Button.SendClicked () [0x00000] in D:\a\s\Xamarin.Forms.Core\Button.cs:173
at Xamarin.Forms.Platform.iOS.ButtonElementManager.OnButtonTouchUpInside (Xamarin.Forms.IButtonController element) [0x00009] in D:\a\s\Xamarin.Forms.Platform.iOS\Renderers\ButtonElementManager.cs:86
at Xamarin.Forms.Platform.iOS.ButtonRenderer.OnButtonTouchUpInside (System.Object sender, System.EventArgs eventArgs) [0x00000] in D:\a\s\Xamarin.Forms.Platform.iOS\Renderers\ButtonRenderer.cs:189
at UIKit.UIControlEventProxy.Activated () [0x00004] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIControl.cs:38
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at RegionInitialize.iOS.Application.Main (System.String[] args) [0x00001] in /Users/lestersconyers/Downloads/RegionInitialize/RegionInitialize/RegionInitialize.iOS/Main.cs:17
我下载了示例 运行 它没有问题,如果你直接 运行 示例你会遇到问题吗?因为从你的日志来看,这和我有点不同。
这是
yours:/Users/lestersconyers/Downloads/RegionInitialize/RegionInitialize/RegionInitialize.iOS/Main.cs:17
这是mine:D:\MyTestPlace\xamarin\PrismRegionsXFSample\RegionPrismSample.iOS\Main.cs
好像有点不一样
从日志中可以看出,问题发生在这一行:
在 RegionInitialize.ViewModels.MainPageViewModel.Test () [0x00001] 在 /Users/lestersconyers/Downloads/RegionInitialize/RegionInitialize/RegionInitialize/ViewModels/MainPageViewModel.cs:39
而其他的则与框架相关。在我下载的示例中,MainPageViewModel.cs
中没有第 39 行
所以我认为这可能是您 MainPageViewModel.cs 文件中 Initialize 函数的一些问题。
我在从 Prism 的部分视图支持迁移到使用区域时遇到问题。问题出现在下面的示例中。我在 Prism.Forms 8 + Xamarin.Forms 5.
的其他项目中遇到了同样的问题https://github.com/CrossGeeks/PrismRegionsXFSample
System.Collections.Generic.KeyNotFoundException: The region manager does not contain the ContentRegion region.
at Prism.Regions.RegionCollection.get_Item (System.String regionName) [0x0000f] in /_/src/Forms/Prism.Forms.Regions/Regions/RegionCollection.cs:43
at Prism.Regions.RegionManager.RequestNavigate (System.String regionName, System.Uri target, System.Action`1[T] navigationCallback, Prism.Navigation.INavigationParameters navigationParameters) [0x00013] in /_/src/Forms/Prism.Forms.Regions/Regions/RegionManager.cs:44
at Prism.Regions.RegionManager.RequestNavigate (System.String regionName, System.Uri target, System.Action`1[T] navigationCallback) [0x00000] in /_/src/Forms/Prism.Forms.Regions/Regions/RegionManager.cs:37
at Prism.Regions.IRegionManagerExtensions.RequestNavigate (Prism.Regions.IRegionManager regionManager, System.String regionName, System.String target, System.Action`1[T] navigationCallback) [0x00024] in /_/src/Forms/Prism.Forms.Regions/Regions/IRegionManagerExtensions.cs:40
at RegionInitialize.ViewModels.MainPageViewModel.Test () [0x00001] in /Users/lestersconyers/Downloads/RegionInitialize/RegionInitialize/RegionInitialize/ViewModels/MainPageViewModel.cs:39
at Prism.Commands.DelegateCommand.Execute () [0x00000] in /_/src/Prism.Core/Commands/DelegateCommand.cs:49
at Prism.Commands.DelegateCommand.Execute (System.Object parameter) [0x00000] in /_/src/Prism.Core/Commands/DelegateCommand.cs:67
at Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.Execute (System.Object parameter) [0x00000] in /_/src/Prism.Core/Commands/DelegateCommandBase.cs:62
at Xamarin.Forms.ButtonElement.ElementClicked (Xamarin.Forms.VisualElement visualElement, Xamarin.Forms.Internals.IButtonElement ButtonElementManager) [0x00008] in D:\a\s\Xamarin.Forms.Core\ButtonElement.cs:60
at Xamarin.Forms.Button.SendClicked () [0x00000] in D:\a\s\Xamarin.Forms.Core\Button.cs:173
at Xamarin.Forms.Platform.iOS.ButtonElementManager.OnButtonTouchUpInside (Xamarin.Forms.IButtonController element) [0x00009] in D:\a\s\Xamarin.Forms.Platform.iOS\Renderers\ButtonElementManager.cs:86
at Xamarin.Forms.Platform.iOS.ButtonRenderer.OnButtonTouchUpInside (System.Object sender, System.EventArgs eventArgs) [0x00000] in D:\a\s\Xamarin.Forms.Platform.iOS\Renderers\ButtonRenderer.cs:189
at UIKit.UIControlEventProxy.Activated () [0x00004] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIControl.cs:38
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at RegionInitialize.iOS.Application.Main (System.String[] args) [0x00001] in /Users/lestersconyers/Downloads/RegionInitialize/RegionInitialize/RegionInitialize.iOS/Main.cs:17
我下载了示例 运行 它没有问题,如果你直接 运行 示例你会遇到问题吗?因为从你的日志来看,这和我有点不同。
这是
yours:/Users/lestersconyers/Downloads/RegionInitialize/RegionInitialize/RegionInitialize.iOS/Main.cs:17
这是mine:D:\MyTestPlace\xamarin\PrismRegionsXFSample\RegionPrismSample.iOS\Main.cs
好像有点不一样
从日志中可以看出,问题发生在这一行: 在 RegionInitialize.ViewModels.MainPageViewModel.Test () [0x00001] 在 /Users/lestersconyers/Downloads/RegionInitialize/RegionInitialize/RegionInitialize/ViewModels/MainPageViewModel.cs:39 而其他的则与框架相关。在我下载的示例中,MainPageViewModel.cs
中没有第 39 行所以我认为这可能是您 MainPageViewModel.cs 文件中 Initialize 函数的一些问题。