Caliburn-Micro / Caliburn.Micro

A small, yet powerful framework, designed for building applications across all XAML platforms. Its strong support for MV* patterns will enable you to build your solution quickly, without the need to sacrifice code quality or testability.
http://caliburnmicro.com/
MIT License
2.79k stars 776 forks source link

Cannot find view for ViewModels create with interceptor #900

Open 1130685535 opened 2 months ago

1130685535 commented 2 months ago

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();, 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");
vb2ae commented 2 months ago

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?

1130685535 commented 2 months ago

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.