gpt4 book ai didi

c# - Prism 对话框 : Unable to resolve Resolution root Object

转载 作者:行者123 更新时间:2023-12-04 08:15:28 39 4
gpt4 key购买 nike

我用 Prism 8.0.0.1909 和 dotnet core 3.1 和 5 试过这个。
对于我的对话,我有一个看法:

<UserControl
x:Class="xzy.Modules.CapillaryBatchwise.Dialogs.NewBatchDialog"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
...
</UserControl>
和一个现在什么都没有的 View 模型:
namespace zxy.Modules.CapillaryBatchwise.ViewModels
{
public class NewBatchDialogViewModel : BindableBase, IDialogAware
{
...
public string Title => "MyTitle";
public event Action<IDialogResult> RequestClose;
public bool CanCloseDialog() => true;

public void OnDialogClosed()
{ }

public void OnDialogOpened(IDialogParameters parameters)
{ }
}
}
我在 App.xaml.cs 中注册了 View 和 View 模型
namespace xyz.CapillaryJournal
{
public partial class App
{
...
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterDialog<NewBatchDialog, NewBatchDialogViewModel>();
}
}}
然后从我的实际 ViewModel 中调用它
 public class CapillaryBatchNavigationViewModel : BindableBase
{
private readonly IDialogService dialogService;

public CapillaryBatchNavigationViewModel(//...
IDialogService dialogService)
{
///...
ShowNewBatchDialogCommand = new DelegateCommand(ShowNewBatchDialog);
this.dialogService = dialogService;
//...
}
public DelegateCommand ShowNewBatchDialogCommand { get; }
private void ShowNewBatchDialog()
{
dialogService.ShowDialog(nameof(ShowNewBatchDialog));
}
//...
}
但是,当我从 View 中调用 ShowNewBatchDialogCommand 时,我得到了这个异常,我无法理解:
Prism.Ioc.ContainerResolutionException: 'An unexpected error occurred while resolving 'System.Object', with the service name 'ShowNewBatchDialog''

Inner Exception
ContainerException: code: Error.UnableToResolveFromRegisteredServices;
message: Unable to resolve Resolution root Object {ServiceKey="ShowNewBatchDialog"}
from container without scope
with Rules with {TrackingDisposableTransients, UseDynamicRegistrationsAsFallbackOnly, FuncAndLazyWithoutRegistration, SelectLastRegisteredFactory} and without {ThrowOnRegisteringDisposableTransient, UseFastExpressionCompilerIfPlatformSupported}
with FactorySelector=SelectLastRegisteredFactory
with Made={FactoryMethod=ConstructorWithResolvableArguments}
with normal and dynamic registrations:
("NewBatchDialog", {FactoryID=160, ImplType=xyy.Modules.CapillaryBatchweise.Dialogs.NewBatchDialog, Reuse=TransientReuse}) ("TaskPresenter", {FactoryID=177, ImplType=xyy.Modules.CapillaryBatchweise.Views.TaskPresenter, Reuse=TransientReuse})
这基本上是对本文档中所做的稍作修改: https://prismlibrary.com/docs/wpf/dialog-service.html
我无法发现我的代码有什么问题。

最佳答案

您应该调用 dialogService.ShowDialog(nameof(NewBatchDialog));由于 View 的名称 NewBatchDialogShowNewBatchDialog是一些不相关的方法的名称。
或者您可以使用特定名称注册 View ,例如 containerRegistry.RegisterDialog<NewBatchDialog, NewBatchDialogViewModel>( "ShowNewBatchDialog" ); ...

关于c# - Prism 对话框 : Unable to resolve Resolution root Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65724956/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com