Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find view for ViewModels create with interceptor #900

Open
1130685535 opened this issue May 16, 2024 · 2 comments
Open

Cannot find view for ViewModels create with interceptor #900

1130685535 opened this issue May 16, 2024 · 2 comments

Comments

@1130685535
Copy link

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");
@1130685535 1130685535 changed the title Cannot find view for ViewModels create by interceptor Cannot find view for ViewModels create with interceptor May 16, 2024
@vb2ae
Copy link
Member

vb2ae commented May 16, 2024

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants