Quantcast
Channel: MVVM Light Toolkit
Viewing all 1826 articles
Browse latest View live

Commented Unassigned: Xamarin Evolve demo NavigationService & nuget v5.0.2 is different [7675]

$
0
0
I tried to reproduce your Xamarin Evolve demo and I'm facing an issue with the NavigationService.

__Configure method problem:__

Xamarin Evolve Configure signature
```
public void Configure(string pageKey, Type pageType)
```

GalaSoft.MvvmLight.Platform (Android) Configure signature
```
public void Configure(string key, Type activityType)
```

GalaSoft.MvvmLight.Platform (iOS)
```
public void Configure(string key, Type controllerType)
```

GalaSoft.MvvmLight.Platform (WPSL81) Configure signature
```
public void Configure(string key, Uri targetUri)
```

Do you think it would be possible to add the same signature on the WPSL81 version?

__Initiliaze method problem__

Xamarin Evolve has an Initiliaze methods for all three platforms.
```
public void Initialize(NavigationPage navigation)
```

There is only one specific for iOS
```
public void Initialize(UINavigationController navigation)
```
Comments: Thanks for your quick reply Laurent, Looking at the code of your demo at Xamarin Evolve, all the code that is related to the navigation is in the PCL project. The NavigationService class seems to be platform agnostic in the Evolve demo project, and the configuration code could be shared across all platforms.

Commented Unassigned: Xamarin Evolve demo NavigationService & nuget v5.0.2 is different [7675]

$
0
0
I tried to reproduce your Xamarin Evolve demo and I'm facing an issue with the NavigationService.

__Configure method problem:__

Xamarin Evolve Configure signature
```
public void Configure(string pageKey, Type pageType)
```

GalaSoft.MvvmLight.Platform (Android) Configure signature
```
public void Configure(string key, Type activityType)
```

GalaSoft.MvvmLight.Platform (iOS)
```
public void Configure(string key, Type controllerType)
```

GalaSoft.MvvmLight.Platform (WPSL81) Configure signature
```
public void Configure(string key, Uri targetUri)
```

Do you think it would be possible to add the same signature on the WPSL81 version?

__Initiliaze method problem__

Xamarin Evolve has an Initiliaze methods for all three platforms.
```
public void Initialize(NavigationPage navigation)
```

There is only one specific for iOS
```
public void Initialize(UINavigationController navigation)
```
Comments: After reviewing the code again, it is Platform agnostic in Xamarin Forms world...

Commented Unassigned: Xamarin Evolve demo NavigationService & nuget v5.0.2 is different [7675]

$
0
0
I tried to reproduce your Xamarin Evolve demo and I'm facing an issue with the NavigationService.

__Configure method problem:__

Xamarin Evolve Configure signature
```
public void Configure(string pageKey, Type pageType)
```

GalaSoft.MvvmLight.Platform (Android) Configure signature
```
public void Configure(string key, Type activityType)
```

GalaSoft.MvvmLight.Platform (iOS)
```
public void Configure(string key, Type controllerType)
```

GalaSoft.MvvmLight.Platform (WPSL81) Configure signature
```
public void Configure(string key, Uri targetUri)
```

Do you think it would be possible to add the same signature on the WPSL81 version?

__Initiliaze method problem__

Xamarin Evolve has an Initiliaze methods for all three platforms.
```
public void Initialize(NavigationPage navigation)
```

There is only one specific for iOS
```
public void Initialize(UINavigationController navigation)
```
Comments: Laurent, you can close both issues I have opened. There is no bug at all... I am the bug :) I watched again your video, and you clearly says that there is a limitation with nuget that prevent having your NavigationService & DialogService helpers in the current packages! Thanks Laurent!

Commented Unassigned: DialogService throws in Xamarin Android [7674]

$
0
0
The DialogService is working fine on iOS and Windows Phone, but it throws in Android.

To reproduce the bug:
Create a new Shared Project (Blank App Xamarin Forms)
Right click solution and add MVVM Light Libraries only on all three project
Uncheck Fast Deploy in Android project properties
Add in App.cs (in shared project) at the beginning of GetMainPage()

```
var srv = new DialogService();
srv.ShowMessage("test", "test");
```

Run Windows Phone, it's fine

Run Android it throws with this exception:

```
{Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00084] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:896
at Android.Runtime.JNIEnv.FinishCreateInstance (IntPtr instance, IntPtr jclass, IntPtr constructorId, Android.Runtime.JValue[] constructorParameters) [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:288
at Android.App.AlertDialog+Builder..ctor (Android.Content.Context context) [0x000ef] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.App.AlertDialog.cs:73
at GalaSoft.MvvmLight.Views.DialogService.CreateBuilder (System.String message, System.String title, System.String buttonConfirmText, System.String buttonCancelText, System.Action afterHideCallback, System.Action`1 afterHideCallbackWithResponse, System.Action`1 afterHideInternal) [0x00022] in c:\MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Platform (Android)\Views\DialogService.cs:222
at GalaSoft.MvvmLight.Views.DialogService.ShowMessage (System.String message, System.String title) [0x00006] in c:\MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Platform (Android)\Views\DialogService.cs:103
at AppT.App.GetMainPage () [0x00008] in c:\DevTests\AppT\AppT\AppT\App.cs:18
--- End of managed exception stack trace ---
java.lang.NullPointerException
at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
at appt.droid.MainActivity.n_onCreate(Native Method)
at appt.droid.MainActivity.onCreate(MainActivity.java:28)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
}
```




Comments: Same problem with my previous issue, I didn't use the Xamarin Evolve implementation.

New Post: RaisePropertyChanged Through Attributes?

$
0
0
I have seen many post regarding a more simple method in creating a bind to the INotifyPropertyChanged events.

We are now adding RaisePropertyChanged( ()=> WelcomeTitle );
To the Setter of the property, this could be simplified?
Where we could be using:

[RaisePropertyChanged]
public string WelcomeTitle {get;set;}

Or

[RaisePropertyChanged]
public class MainViewModel : ViewModelBase
** Allowing ALL the propertied to have the INotifyPropertyChanged implemented...

Is this possible, and how hard is this to implement?
-Don

New Post: adding a method to detach a command in Mvvm Light (Android)

$
0
0
In Mvvlight for android, I notice that there is a mean to detach a binding through the extension method Detach(). But there is no way to detach a command after setting it with SetCommand() Extension Method. I wonder why this is missing ? Is it too hard to implement such a method through .net reflexion ?

New Post: CanExecute Method still can not work in WPF with latest MvvmLight version on Nuget

$
0
0
As far as I know, RaiseCanExecuteChanged is not new at all, it's been there for years. However, you shouldn't need to use it.

The problem you're seeing can be fixed by changing your "using" statement from GalaSoft.MvvmLight.Command to GalaSoft.MvvmLight.CommandWpf. I saw a blog post by the author of this toolkit, explaining why this was necessary, but can't remember where it was. You can probably find it with some searching. However, just adding "Wpf" to the end of the using will fix your problem without you having to call RaiseCanExecuteChanged yourself.

New Post: Should the viewmodel be opening windows?

$
0
0
I see a lot of people saying that if you want to open a child window, the button on your view should bind to a vm command, and that command should send a message that the view picks up.

Isn't this an overly complex way of doing it? The view is telling the vm, "please instruct me to open a window," which seems pointless. The view already knows it needs to do this, so why bother involving the vm?

Apart from the obvious problem of extra complexity, you're adding more code to the view, as it has to register/deregister for messages, pick up incoming messages, check it's relevant and only then open the window. Something that can be done with one or two lines of view code becomes a convoluted trail of extra code in both view and vm.

Furthermore, if I come to look at someone's code, and want to follow the path of execution, I have to find all places where this message type is used, then see which of these is the one I want. If we use a new message type for every situation, we end up with an explosion of types, whereas if we reuse them, we obfuscate the code("now, which of these 27 methods that picks up FerretMessage is the one I want?"), and make it much harder to follow what's going on, and increasing the chance of bugs when something else picks up on the message.

Messages are great when you want to broadcast something, and you don't know (or care) who picks up the message, but using one in this case seems totally the wrong thing to do.

Don't get me wrong, I'm all for keeping code out of the view where possible, but here you're adding more code to the view, and needlessly involving the view model.

Can someone explain the point of doing it this way, as it seems wrong to me.

New Post: Should the viewmodel be opening windows?

$
0
0
Hi,

I completely agree with you. Only put in the VM what should be tested by unit tests, shared with other projects, etc. If you have some view-only code, it is perfectly OK to leave it in the view only. If you need to compute some condition deciding if the child window should be opened or not, it is OK to create a method doing the calculation and returning a value, and to have the view call this method.

Cheers
Laurent

New Post: Should the viewmodel be opening windows?

$
0
0
Thanks for that. Maybe I can extend this and ask a related question, as we have been debating this issue in our team.

Suppose you have a window showing details of a sales quote (for example), and you want to allow the user to click a button to open a child window to pick the customer. I am in favour of doing something like this in the button's click event handler...
private void PickCustomer_Click(object sender, RoutedEventArgs e) {
  PickCustomerWindow pcw = new PickCustomerWindow();
  pcw.Closing += (_, __) => {
    if (pcw.Customer != null) {
      ((QuoteDetailsViewModel)DataContext).SetCustomer(pcw.Customer);
    }
  };
  pcw.ShowDialog(this);
}
The PickCustomerWindow window has a Customer property, which does nothing more than return the view model's SelectedCustomer property.

The reason I like this approach is that I can see immediately what's happening when the user clicks the button. The window is opened, and then when it closes, if they have picked a customer, that is passed down to the vm, where it will be set on the underlying entity, and the changes reflected in the view due to the binding being updated. If I want to see what happens in the VM when a customer is picked, I can put my cursor on the SetCustomer() method and click f12 (gotta love Visual Studio's shortcuts!), and I am taken right to the code.

You could simplify this even more by removing the null check, and doing that in the vm. That makes the view code even simpler, although I'm not sure the benefit is particularly great.

The other view is to have the PickCustomerWindow send out a message saying a customer has been picked, and have the quote window's vm pick up that message and set the customer on the quote. Like I mentioned in my first post, this obfuscates the code, and wastes a lot of time searching around to find where the message is picked up, as well as having the issue of messages being picked up by the wrong code, or a profusion of very specialist messages.

My view is that given that the quote window knows exactly who needs to know about the picked customer, and has immediate access to the vm, I don't see what's wrong with pushing the customer down to the vm from the view. I'm not adding any testable logic to the view, it's very simple code. As I said, even the null check could be removed it you wanted.

Furthermore, if you use a message, and want to test the vm, you have to have some way of simulating the message. That probably means making the vm's ProcessMessage method public, and accessing it in the unit test. This feels really wrong, this method is private, and should stay private. The method I showed above doesn't have this problem, as you can just create a Customer entity in the unit test and pass it into the vm's SetCustomer() method.

What would you think to this scenario? Would you still be happy to have the code in the view, or would you feel a message is more appropriate here? If the latter, please can you explain what benefit a message has, as I really can't see any, but can see a few significant disadvantages.

Thanks again.

Created Unassigned: conflict between dll's [7677]

$
0
0
Hi,

I had been using 4.4.32.1 of mvvmlight, and recently updated to the latest version 5.0.2 using the package manager. it seem to install ok, but when I went to build the project I was receiving a conflicting dll error.

The system, mscorlib and system.runtime were the dlls it was complaining about, after much checking I discovered that the issue appears to be with Microsoft.Practices.ServiceLocation.dll and the fact that is seems to be referenced against .net 2.0.0.5. I couldn't find a new version of this dll, so to test that I was in the right area I rolled mvvmlight back to 4.4.32.1 and sure enough it all compiled correctly.

Just wondering is there an issue with 5.0.2 and the Microsoft.Practices.ServiceLocation.dll? is there something else I need to be doing when using 5.0.2?

I will try updating it again now I know what to do to get it back, to see if it was just a one off issue.

Cheers

New Post: Binaries for VS2010 developers

$
0
0
It would be very nice if separate binaries of latest version will be also available for download for Visual Studio 2010 developers.

Commented Issue: Relay Command CanExecute() not working in WPF [7659]

$
0
0
After updating to version 5 the CanExecute() stopped working correctly. It validates the first time, like when the window is open, but it won't make any more validations after that.
Comments: Laurent, I think there is a problem when CanExecute is passed as lambda in constructor. It executes a couple of times and then stops. Perhaps it has something to do with WeakReference, I am not sure. If I instead implement an instance method it works just fine.

Commented Issue: Relay Command CanExecute() not working in WPF [7659]

$
0
0
After updating to version 5 the CanExecute() stopped working correctly. It validates the first time, like when the window is open, but it won't make any more validations after that.
Comments: Hi, Please post a repro, Thanks Laurent

New Post: Multiple instances of viewmodel

$
0
0
Hi,

how do I create multiple instances of the same usercontrol? I have a listview and a tabcontrol. When I click a listviewitem a new tab gets created with the usercontrol as content. However when I click multiple listviewitems, all the tabs are synced with the last selected listviewitem.

How can I prevent this and make each usercontrol unique?

I am using mvvm light and wpf

thanks

New Post: DialogMessage and Dialog Boxes

$
0
0
It took me quite long time to get as much informations about MVVM pattern with user input dialogs (MessageBox, OpenFileDialog, etc.) as possible. Solutions I found were either too much complicated or involved lot of XAML code which I really hate.
My solution is about creating dialog service which is class that have references to UI namespace and have method to get needed values. This method get values from user by showing appropriate user interface.
Dialog service instance is injected into viewmodels using SimpleIoC container and then used inside viewmodel when needed.
I think this approach is good, what do you think?

P.S. I love MVVM Light framework, it is very simple yet very powerful. Things like Unity, Prism or Windsor are overengineered monstrosities.

Created Unassigned: The name "ViewModelLocator" does not exist in the namespace "using:XXX.ViewModel" [7678]

$
0
0
Hi,

I am getting the error
The name "ViewModelLocator" does not exist in the namespace "using:MyApp.ViewModel"
in the app.xaml file of a universal application. I am using v5.020 of mvvm light.

Browsing the web I have read solutions such as:
-Cleaning and rebuilding the project
-Placing the
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:MyApp.ViewModel"/>
line inside a resource dictionary
-Leaving only the above line in the Application.resources
-Uninstalling and re-installing mvvm

I have tried the above with no success.

I would also like to note that the error is not encountered in the WindowsPhone8.1(winrt) project and the app runs fine. Only in the Windows 8.1 project does the error show up.

If this error is not resolved I won't be able to reference any of my ViewModels which is obviously a huge problem.

Below are my App.xaml file and an abbreviated version of my ViewModelLocator

App.xaml
```
<Application x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Colors.xaml" />
<ResourceDictionary Source="/Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:MyApp.ViewModel"/>
</ResourceDictionary>
</Application.Resources>
</Application>
```

ViewModelLocator.cs
```
namespace MyApp.ViewModel
{
/// <summary>
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
/// </summary>
public class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

////if (ViewModelBase.IsInDesignModeStatic)
////{
//// // Create design time view services and models
//// SimpleIoc.Default.Register<IDataService, DesignDataService>();
////}
////else
////{
//// // Create run time view services and models
//// SimpleIoc.Default.Register<IDataService, DataService>();
////}
var navigationService = this.CreateNavigationService();


SimpleIoc.Default.Register<LoginPageViewModel>();
SimpleIoc.Default.Register<LoginRegisterPageViewModel>();
........
........
SimpleIoc.Default.Register<StoresPageViewModel>();
SimpleIoc.Default.Register<INavigationService>(() => navigationService);
SimpleIoc.Default.Register<IEncryptService, EncryptService>();
SimpleIoc.Default.Register<ISettingsService, SettingsService>();

}

public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}

public ConnectionsPageViewModel Connections
{
get
{
return ServiceLocator.Current.GetInstance<ConnectionsPageViewModel>();
}
}

public ConnectionDetailPageViewModel ConnectionDetails
{
get
{
return ServiceLocator.Current.GetInstance<ConnectionDetailPageViewModel>();
}
}

........
........

public StoresPageViewModel Stores
{
get
{
return ServiceLocator.Current.GetInstance<StoresPageViewModel>();
}
}


private INavigationService CreateNavigationService()
{
var navigationService = new NavigationService();
navigationService.Configure("ConnectionsPage", typeof(ConnectionsPage));
navigationService.Configure("ConnectionDetailsPage", typeof(ConnectionDetailsPage));
navigationService.Configure("BlockSimPage", typeof(BlockSimPage));
navigationService.Configure("MainPage", typeof(MainPage));
#if WINDOWS_PHONE_APP
navigationService.Configure("LoginRegisterPage", typeof(LoginRegisterPage));
navigationService.Configure("LoginPage", typeof(LoginPage));
navigationService.Configure("RegisterPage", typeof(RegisterPage));
navigationService.Configure("RegisterPage2", typeof(RegisterPage2));
navigationService.Configure("RegisterPage3", typeof(RegisterPage3));
navigationService.Configure("InvoiceLabelDetailsPage", typeof(InvoiceLabelDetailsPage));
navigationService.Configure("InvoiceChartPage", typeof(InvoicesChartPage));
navigationService.Configure("InvoiceDetails", typeof(InvoiceDetailsPage));
#endif


return navigationService;
}

public static void Cleanup()
{
// TODO Clear the ViewModels
}
}
}
```

Edited Unassigned: The name "ViewModelLocator" does not exist in the namespace "using:XXX.ViewModel" [7678]

$
0
0
Hi,

I am getting the error
The name "ViewModelLocator" does not exist in the namespace "using:MyApp.ViewModel"
in the app.xaml file of a universal application. I am using v5.020 of mvvm light.

Browsing the web I have read solutions such as:
-Cleaning and rebuilding the project
-Placing the
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:MyApp.ViewModel"/>
line inside a resource dictionary
-Leaving only the above line in the Application.resources
-Uninstalling and re-installing mvvm

I have tried the above with no success.

I would also like to note that the error is not encountered in the WindowsPhone8.1(winrt) project and the app runs fine. Only in the Windows 8.1 project does the error show up.

If this error is not resolved I won't be able to reference any of my ViewModels which is obviously a huge problem.

Below are my App.xaml file and an abbreviated version of my ViewModelLocator

Thanks for any help concerning this matter. And thanks again for a great framework :)

App.xaml
```
<Application x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Colors.xaml" />
<ResourceDictionary Source="/Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:MyApp.ViewModel"/>
</ResourceDictionary>
</Application.Resources>
</Application>
```

ViewModelLocator.cs
```
namespace MyApp.ViewModel
{
/// <summary>
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
/// </summary>
public class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

////if (ViewModelBase.IsInDesignModeStatic)
////{
//// // Create design time view services and models
//// SimpleIoc.Default.Register<IDataService, DesignDataService>();
////}
////else
////{
//// // Create run time view services and models
//// SimpleIoc.Default.Register<IDataService, DataService>();
////}
var navigationService = this.CreateNavigationService();


SimpleIoc.Default.Register<LoginPageViewModel>();
SimpleIoc.Default.Register<LoginRegisterPageViewModel>();
........
........
SimpleIoc.Default.Register<StoresPageViewModel>();
SimpleIoc.Default.Register<INavigationService>(() => navigationService);
SimpleIoc.Default.Register<IEncryptService, EncryptService>();
SimpleIoc.Default.Register<ISettingsService, SettingsService>();

}

public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}

public ConnectionsPageViewModel Connections
{
get
{
return ServiceLocator.Current.GetInstance<ConnectionsPageViewModel>();
}
}

public ConnectionDetailPageViewModel ConnectionDetails
{
get
{
return ServiceLocator.Current.GetInstance<ConnectionDetailPageViewModel>();
}
}

........
........

public StoresPageViewModel Stores
{
get
{
return ServiceLocator.Current.GetInstance<StoresPageViewModel>();
}
}


private INavigationService CreateNavigationService()
{
var navigationService = new NavigationService();
navigationService.Configure("ConnectionsPage", typeof(ConnectionsPage));
navigationService.Configure("ConnectionDetailsPage", typeof(ConnectionDetailsPage));
navigationService.Configure("BlockSimPage", typeof(BlockSimPage));
navigationService.Configure("MainPage", typeof(MainPage));
#if WINDOWS_PHONE_APP
navigationService.Configure("LoginRegisterPage", typeof(LoginRegisterPage));
navigationService.Configure("LoginPage", typeof(LoginPage));
navigationService.Configure("RegisterPage", typeof(RegisterPage));
navigationService.Configure("RegisterPage2", typeof(RegisterPage2));
navigationService.Configure("RegisterPage3", typeof(RegisterPage3));
navigationService.Configure("InvoiceLabelDetailsPage", typeof(InvoiceLabelDetailsPage));
navigationService.Configure("InvoiceChartPage", typeof(InvoicesChartPage));
navigationService.Configure("InvoiceDetails", typeof(InvoiceDetailsPage));
#endif


return navigationService;
}

public static void Cleanup()
{
// TODO Clear the ViewModels
}
}
}
```

Edited Unassigned: The name "ViewModelLocator" does not exist in the namespace "using:XXX.ViewModel" [7678]

$
0
0
Hi,

I am getting the error
The name "ViewModelLocator" does not exist in the namespace "using:MyApp.ViewModel"
in the app.xaml file of a universal application. I am using v5.020 of mvvm light.

Browsing the web I have read solutions such as:
-Cleaning and rebuilding the project
-Placing the
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:MyApp.ViewModel"/>
line inside a resource dictionary
-Leaving only the above line in the Application.resources
-Uninstalling and re-installing mvvm

I have tried the above with no success.

I would also like to note that the error is not encountered in the WindowsPhone8.1(winrt) project and the app runs fine. Only in the Windows 8.1 project does the error show up.

If this error is not resolved I won't be able to reference any of my ViewModels which is obviously a huge problem.

Below are my App.xaml file and an abbreviated version of my ViewModelLocator

Thanks for any help concerning this matter. And thanks again for a great framework :)

App.xaml
```
<Application x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Colors.xaml" />
<ResourceDictionary Source="/Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:MyApp.ViewModel"/>
</ResourceDictionary>
</Application.Resources>
</Application>
```

ViewModelLocator.cs
```
namespace MyApp.ViewModel
{
/// <summary>
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
/// </summary>
public class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

////if (ViewModelBase.IsInDesignModeStatic)
////{
//// // Create design time view services and models
//// SimpleIoc.Default.Register<IDataService, DesignDataService>();
////}
////else
////{
//// // Create run time view services and models
//// SimpleIoc.Default.Register<IDataService, DataService>();
////}
var navigationService = this.CreateNavigationService();


SimpleIoc.Default.Register<LoginPageViewModel>();
SimpleIoc.Default.Register<LoginRegisterPageViewModel>();
........
........
SimpleIoc.Default.Register<StoresPageViewModel>();
SimpleIoc.Default.Register<INavigationService>(() => navigationService);
SimpleIoc.Default.Register<IEncryptService, EncryptService>();
SimpleIoc.Default.Register<ISettingsService, SettingsService>();

}

public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}

public ConnectionsPageViewModel Connections
{
get
{
return ServiceLocator.Current.GetInstance<ConnectionsPageViewModel>();
}
}

public ConnectionDetailPageViewModel ConnectionDetails
{
get
{
return ServiceLocator.Current.GetInstance<ConnectionDetailPageViewModel>();
}
}

........
........

public StoresPageViewModel Stores
{
get
{
return ServiceLocator.Current.GetInstance<StoresPageViewModel>();
}
}


private INavigationService CreateNavigationService()
{
var navigationService = new NavigationService();
navigationService.Configure("ConnectionsPage", typeof(ConnectionsPage));
navigationService.Configure("ConnectionDetailsPage", typeof(ConnectionDetailsPage));
navigationService.Configure("BlockSimPage", typeof(BlockSimPage));
navigationService.Configure("MainPage", typeof(MainPage));
#if WINDOWS_PHONE_APP
navigationService.Configure("LoginRegisterPage", typeof(LoginRegisterPage));
navigationService.Configure("LoginPage", typeof(LoginPage));
navigationService.Configure("RegisterPage", typeof(RegisterPage));
navigationService.Configure("RegisterPage2", typeof(RegisterPage2));
navigationService.Configure("RegisterPage3", typeof(RegisterPage3));
navigationService.Configure("InvoiceLabelDetailsPage", typeof(InvoiceLabelDetailsPage));
navigationService.Configure("InvoiceChartPage", typeof(InvoicesChartPage));
navigationService.Configure("InvoiceDetails", typeof(InvoiceDetailsPage));
#endif


return navigationService;
}

public static void Cleanup()
{
// TODO Clear the ViewModels
}
}
}
```

EDIT1: After reading [this](https://mvvmlight.codeplex.com/discussions/547269) and changing the target platform the error goes away for x86 architecture. However I need to develop and test for ARM devices and the error still exists there.

Commented Unassigned: The name "ViewModelLocator" does not exist in the namespace "using:XXX.ViewModel" [7678]

$
0
0
Hi,

I am getting the error
The name "ViewModelLocator" does not exist in the namespace "using:MyApp.ViewModel"
in the app.xaml file of a universal application. I am using v5.020 of mvvm light.

Browsing the web I have read solutions such as:
-Cleaning and rebuilding the project
-Placing the
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:MyApp.ViewModel"/>
line inside a resource dictionary
-Leaving only the above line in the Application.resources
-Uninstalling and re-installing mvvm

I have tried the above with no success.

I would also like to note that the error is not encountered in the WindowsPhone8.1(winrt) project and the app runs fine. Only in the Windows 8.1 project does the error show up.

If this error is not resolved I won't be able to reference any of my ViewModels which is obviously a huge problem.

Below are my App.xaml file and an abbreviated version of my ViewModelLocator

Thanks for any help concerning this matter. And thanks again for a great framework :)

App.xaml
```
<Application x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Colors.xaml" />
<ResourceDictionary Source="/Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:MyApp.ViewModel"/>
</ResourceDictionary>
</Application.Resources>
</Application>
```

ViewModelLocator.cs
```
namespace MyApp.ViewModel
{
/// <summary>
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
/// </summary>
public class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

////if (ViewModelBase.IsInDesignModeStatic)
////{
//// // Create design time view services and models
//// SimpleIoc.Default.Register<IDataService, DesignDataService>();
////}
////else
////{
//// // Create run time view services and models
//// SimpleIoc.Default.Register<IDataService, DataService>();
////}
var navigationService = this.CreateNavigationService();


SimpleIoc.Default.Register<LoginPageViewModel>();
SimpleIoc.Default.Register<LoginRegisterPageViewModel>();
........
........
SimpleIoc.Default.Register<StoresPageViewModel>();
SimpleIoc.Default.Register<INavigationService>(() => navigationService);
SimpleIoc.Default.Register<IEncryptService, EncryptService>();
SimpleIoc.Default.Register<ISettingsService, SettingsService>();

}

public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}

public ConnectionsPageViewModel Connections
{
get
{
return ServiceLocator.Current.GetInstance<ConnectionsPageViewModel>();
}
}

public ConnectionDetailPageViewModel ConnectionDetails
{
get
{
return ServiceLocator.Current.GetInstance<ConnectionDetailPageViewModel>();
}
}

........
........

public StoresPageViewModel Stores
{
get
{
return ServiceLocator.Current.GetInstance<StoresPageViewModel>();
}
}


private INavigationService CreateNavigationService()
{
var navigationService = new NavigationService();
navigationService.Configure("ConnectionsPage", typeof(ConnectionsPage));
navigationService.Configure("ConnectionDetailsPage", typeof(ConnectionDetailsPage));
navigationService.Configure("BlockSimPage", typeof(BlockSimPage));
navigationService.Configure("MainPage", typeof(MainPage));
#if WINDOWS_PHONE_APP
navigationService.Configure("LoginRegisterPage", typeof(LoginRegisterPage));
navigationService.Configure("LoginPage", typeof(LoginPage));
navigationService.Configure("RegisterPage", typeof(RegisterPage));
navigationService.Configure("RegisterPage2", typeof(RegisterPage2));
navigationService.Configure("RegisterPage3", typeof(RegisterPage3));
navigationService.Configure("InvoiceLabelDetailsPage", typeof(InvoiceLabelDetailsPage));
navigationService.Configure("InvoiceChartPage", typeof(InvoicesChartPage));
navigationService.Configure("InvoiceDetails", typeof(InvoiceDetailsPage));
#endif


return navigationService;
}

public static void Cleanup()
{
// TODO Clear the ViewModels
}
}
}
```

EDIT1: After reading [this](https://mvvmlight.codeplex.com/discussions/547269) and changing the target platform the error goes away for x86 architecture. However I need to develop and test for ARM devices and the error still exists there.
Comments: Hi, This error is a symptom of something that is going wrong inside your project. The VML is created early in the application lifetime. In turns, it will create other objects that may throw an exception. If this happens, the error shown is the one you describe above. Place a breakpoint in the VML constructor and debug from there. Also make sure to turn on first chance exceptions as that might give you a better idea of what is happening. I am ready to bet that you have something "throwing up" when your application starts up. If I don't hear back I'll close this issue as it is most probably not MVVM Light related ;) Cheers Laurent
Viewing all 1826 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>