[英]Prism binding wrong viewmodel
我刚到达我公司的一个项目(在过去的一年中,有将近五十个人接触代码的那种项目...)
我正在尝试修补一些错误,但我遇到了一些问题。
我们将棱镜与MVVM模型配合使用。
我有一个ContactDetailPage视图,该视图应该在xaml中的以下行绑定到ContactDetailPageVM,我错了吗?
prism:ViewModelLocator.AutoWireViewModel="True"
相反,我不知道为什么,它被绑定到名为ProfilsPagesVM的VM。
任何人都有解决方案来强制对ContactDetailPageVM进行绑定?
经过网络,没有发现与我的问题有关的任何信息。 欢迎任何链接。
为了帮助您,这里提供了ContactDetailPageVM代码:
namespace ViewModels
{
public class ContactDetailPageVM : BaseViewModel
{
private Contact _selectedContact;
public Contact SelectedContact
{
get { return _selectedContact; }
set { _selectedContact = value;}
}
public ContactDetailPageVM()
: base(_navigationService, _auth, _data)
{
}
public override void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, Dictionary<string, object> viewModelState)
{
base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState);
SelectedContact = (Contact)navigationParameter;
}
}
}
如果您需要任何其他详细信息,请问,我很乐意与您分享
AutoWireViewModelChanged逻辑基于命名约定。
/// <summary>
/// The ViewModelLocationProvider class locates the view model for the view that has the AutoWireViewModelChanged attached property set to true.
/// The view model will be located and injected into the view's DataContext. To locate the view, two strategies are used: First the ViewModelLocationProvider
/// will look to see if there is a view model factory registered for that view, if not it will try to infer the view model using a convention based approach.
/// This class also provide methods for registering the view model factories,
/// and also to override the default view model factory and the default view type to view model type resolver.
/// </summary>
var viewModelName = String.Format(CultureInfo.InvariantCulture, "{0}ViewModel, {1}", viewName, viewAssemblyName);
确保视图模型遵循命名约定,例如ContactDetailPage ViewModel 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.