Caliburn.Micro icon indicating copy to clipboard operation
Caliburn.Micro copied to clipboard

Cannot find view for ViewModels create with interceptor

Open 1130685535 opened this issue 1 year ago • 2 comments

I have a MyViewModel class as follows:

public class MyViewModel : Screen, ITransientDependency
{
    [ReapeatClick]
    public void Save()
    {
    }
}

The [ReapeatClick] method attribute uses an interceptor.

In a method ShowView():

private void ShowView()
{
    var vm = IoC.Get<MyViewModel>();
    IWindowManager windowManager = IoC.Get<IWindowManager>();
    var dialogResult = await windowManager.ShowDialogAsync(vm);
}

When obtaining the class with an interceptor using the IoC container: var vm = IoC.Get<MyViewModel>();, the type of vm becomes Castle.Proxies.MyViewModelProxy. However, the View’s name is MyView, which prevents the View from being matched with the ViewModel. I tried the following configuration but still could not locate the View:

ViewLocator.AddNamespaceMapping("Castle.Proxies.*", _viewAssemblyName);
ViewLocator.NameTransformer.AddRule(@"ViewModelProxy$", "View");

1130685535 avatar May 16 '24 03:05 1130685535

What kind of a project is this? (WPF, WPF .net core, Xamarin, etc..) Are you using Castle Core as your di container? Could you share some code?

vb2ae avatar May 16 '24 10:05 vb2ae

What kind of a project is this? (WPF, WPF .net core, Xamarin, etc..) Are you using Castle Core as your di container? Could you share some code?这是一个什么样的项目?(WPF、WPF .net core、Xamarin 等)您是否正在使用 Castle Core 作为您的容器?你能分享一些代码吗?

it is a WPF.net-core project.

1130685535 avatar May 20 '24 06:05 1130685535