Reputation: 471
First, i'm a begginer in silverlight and more in MVVM Light that i had never use before. I'm using VS2013 and I have a silverlight solution who use MVVM Light (i'm not the original developper of this solution). So, i have maybe 8-10 Views and the same number of Views Models who are "linked" through "ViewModelLocator" in the locator repertory (if i have understand good how MVVM works).
My job is to remove the locator services from this solution and use directly the code behind the view to make the "link" with the ViewModel, because the locator is not really needed in this solution so they have decided to remove it.
My first idea was to "simply" copy (and make the adjustment necessary) the code in the locator who concern my view in the code behind this view, and remove the datacontext who bind the locator in the view xaml. But it dont works and i see in my debug console a lot of message (but no error or warning) like : "Error System.Windows.Data : error with the path BindingExpression : property 'User' not found on 'Info.ViewModel.ViewModel_Content'.........
I think i should miss something but i dont know what, maybe a binding to change or something like this... its like if what I change didnt affect the solution, and now i see much less "things" on my interface when i start it.
What do you think about this please ? What are the correct steps to do for remove the locator services ?
Thank you very much for your help and your advices, and I apologize for my bad english :p
EDIT :
I have forget also to say that i have edit the app.xaml and delete the referency to the ViewModelLocator :
<vm:ViewModelLocator x:Key="Locator"/>
Here you can see a sample of a block code in the ViewModelLocator.cs (there is 7 or 8 like this, one for each view/viewModel) :
private static ViewModel_Ask _Ask;
public ViewModel_Ask Ask
{
get
{
return AskStatic;
}
}
public static void CreateAsk()
{
if (_Ask == null)
{
_Ask = new ViewModel_Ask();
}
}
public static void ClearAsk()
{
_Ask.Cleanup();
_Ask = null;
}
public static ViewModel_Ask AskStatic
{
get
{
if (_Ask == null)
{
CreateAsk();
}
return _Ask;
}
}
EDIT :
Problem solved ! the answer of Mark was right and i have finally resolved my problem. Don't forget to delete the datasource in the view and set the datacontext in each code behind from view. Thanks !
Upvotes: 0
Views: 190
Reputation: 1050
In each view code behind, add to the constructor (or loaded method, etc.):
this.DataContext = Ask;
(obviously, the viewmodel class will differ with each view)
If I understand your post, you've done all of this but #4.
Upvotes: 1