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

Edited Issue: 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.

Closed Issue: iOS - bindings do not work on device [7670]

$
0
0
I have downloaded latest sources and tried to run sample project (Flower) on iOS. App launches fine, but it crashes on following code:

AddCommentViewController, line 28

_commentBinding = this.SetBinding( () => CommentText.Text).UpdateSourceTrigger("Changed");

with "Event not found: changed" message.

Interesting is, that it works in Simulator but not on device.

Closed 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)
```

Edited Issue: 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)
```

Commented Issue: 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: Thanks for the quick answer and the pointers. I'll try that now and get back to you here.

Commented Issue: 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 again, Yes there was something "throwing up" as you said. I removed it and the project works. The error is still showing in the Error List though, only now it magically doesn't affect the project. Thanks for the pointers. I'll have them in mind in case I run into this again. Thanks again.

New Post: How to update from Prism to Mvvmlight ?

$
0
0
Hi,

I am trying to update my previous Silverlight Prism project to Xamarin with MVVMLight support. in previous project, the ViewModel class normally declare like this.

public class FIBMainViewModel : NotificationObject, IPartImportsSatisfiedNotification, INavigationAware
{
//*
   public void OnNavigatedFrom(NavigationContext navigationContext)
    {
        //todo something when leave from the page
    }

    public void OnNavigatedTo(NavigationContext navigationContext)
    {
        // todo something when navigate to this view
    }
}

My question is:
How to update OnNavigatedFrom and OnNavigatedTo method in MvvmLight ?

I appreciate any of your help and sample code.

Many thanks

FENG

Closed Issue: 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.

Edited Issue: 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.

Closed Issue: RaisePropertyChanging gone in V.5 ?! [7662]

$
0
0
Seems like RaisePropertyChanging was removed from the ViewModelBase? I've upgarded from 4.2, and besides the buttons isssue, i'm also having the following:

public class MyBase_ViewModel : ViewModelBase
{
// THIS ONE IS OK
[NotifyPropertyChangedInvocator]
protected override void RaisePropertyChanged([CallerMemberName]string property = "")
{
base.RaisePropertyChanged(property);
}

// THIS ONE IS COMPLAINING ABOUT NO METHOD TO OVERRIDE
[NotifyPropertyChangedInvocator]
protected override void RaisePropertyChanging([CallerMemberName]string property = "")
{
base.RaisePropertyChanging(property);
}
}

shall i just remove it, or are there any other implications involved ?

Edited Issue: RaisePropertyChanging gone in V.5 ?! [7662]

$
0
0
Seems like RaisePropertyChanging was removed from the ViewModelBase? I've upgarded from 4.2, and besides the buttons isssue, i'm also having the following:

public class MyBase_ViewModel : ViewModelBase
{
// THIS ONE IS OK
[NotifyPropertyChangedInvocator]
protected override void RaisePropertyChanged([CallerMemberName]string property = "")
{
base.RaisePropertyChanged(property);
}

// THIS ONE IS COMPLAINING ABOUT NO METHOD TO OVERRIDE
[NotifyPropertyChangedInvocator]
protected override void RaisePropertyChanging([CallerMemberName]string property = "")
{
base.RaisePropertyChanging(property);
}
}

shall i just remove it, or are there any other implications involved ?

Closed 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)
}
```




Edited Issue: 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)
}
```




New Post: Multiple instances of viewmodel

$
0
0
Nobody that can help me ? I have asked the same question on stackoverflow but I don't get an answer there.

I have read about the fact that you can unique initialize your viewmodel in the viewmodellocator by adding a Guid to it:
    public DossierDetailViewModel DossierDetail
    {
        get
        {
            //return ServiceLocator.Current.GetInstance<DossierDetailViewModel>();
            return SimpleIoc.Default.GetInstance<DossierDetailViewModel>(Guid.NewGuid().ToString());
            //return new DossierDetailViewModel();
        }
    }
but I still have the same problem.

Any help is appreciated

New Post: Multiple instances of viewmodel

$
0
0
Hi,

In this situation, I would assign the datacontext in code behind when you create the new tab (assuming that the tab creation is done in code).

You can use the IOC container to create the VM if you need to keep track of it in the registry. If not, you can just get it from a factory method on the main VM.

Then create your Tab and use something like

myTab.DataContext = theNewVm;

Does it make sense?
Cheers
Laurent

New Post: Multiple instances of viewmodel

$
0
0
Hi Laurent, thank you for your help.

The tab is indeed created in code behind. It is created with each click of a listviewitem and added to the tabcontrol. The content of the tab is a usercontrol with its own viewmodel. When I click a few listviewitems then more tabs are created but all with the same usercontrol (and thus viewmodel).

This is the XAML of the TabControl:
<TabControl Grid.Row="0" Grid.Column="1"
            ItemsSource="{Binding Path=OpenDossiers}" SelectedIndex="{Binding SelectedIndex}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <WrapPanel>
                        <TextBlock FontSize="18" Text="{Binding TabName}"/>
                        <Button Command="{Binding CloseDossierCommand}" Content="X" Margin="4,0,0,0" FontFamily="Courier New" Width="17" Height="17" VerticalContentAlignment="Center" />
                    </WrapPanel>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <views:DossierDetailView />
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
It's itemsource is OpenDossiers which is an observablecollection:
    private ObservableCollection<DossierDetailViewModel> _openDossiers;

    public ObservableCollection<DossierDetailViewModel> OpenDossiers
    {
        get
        {
            return _openDossiers;
        }
        set
        {
            _openDossiers = value;
            RaisePropertyChanged("OpenDossiers");
        }
    }
The creation of a new tab is done like this:
            DossierDetailViewModel newDossier = new DossierDetailViewModel();
            newDossier.TabName = SelectedDossier.Omschrijving;
            this.OpenDossiers.Add(newDossier);
            Messenger.Default.Send<DTO.Dossier.Dossier>(SelectedDossier, "SetDossier");
            SelectedIndex = OpenDossiers.IndexOf(newDossier);
As you can see the DossierDetailViewModel is the viewmodel that is used in each tab. The Messenger.Send fills a property of that viewmodel with the selected listviewitem. But when I have multiple tabs and so multiple instances of the usercontrols with the viewmodel every tabs is synced with the last selected listviewitem.

I have tried it with TabItem and DataContext as you suggested but that didn't make a difference. Maybe you can see something wrong in my code or way of thinking :)

New Post: Multiple instances of viewmodel

$
0
0
Hi

At first glance it should work since the datacontext of the DataTemplate (of the TabControl) will be set to the current item in the ObsCollection.

That said I am looking at that on a mobile phone so maybe I missed something. In this scenario, setting the DataContext in code won't help you since it is automatically done at the Data Template level, and then inherited down to the user control.

Do you in any place set the DataContext of the User control itself?

I'll take a closer look at home.

Cheers
Laurent

New Post: Multiple instances of viewmodel

$
0
0
I appreciate your valuable time Laurent.

This is the xaml of my usercontrol. As you can see it has the datacontext of the viewmodel. As a quick test I put the Dossier.Omschrijving (which is a part of the object the usercontrol gets from the selected listviewitem) in a textbox:

<UserControl x:Class="eDossier.WPF.View.DossierDetailView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"             
    xmlns:ignore="http://www.ignore.com"
    mc:Ignorable="d ignore"
    DataContext="{Binding DossierDetail, Source={StaticResource Locator}}">

<Grid >
    <ScrollViewer >
        <StackPanel Grid.Row="2" Grid.Column="0" Margin="0,0,0,5">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="Naam van het dossier" Margin="5" Grid.Column="0" />
                <TextBox Grid.Column="1" Text="{Binding Path=Dossier.Omschrijving}" Controls:TextBoxHelper.Watermark="Omschrijving van het dossier"/>
            </Grid>
        </StackPanel>
    </ScrollViewer>
</Grid>
</UserControl>

With in its viewmodel the property "Dossier" which holds the selected listviewitem and "TabName" which holds the name of the tab:
    private DTO.Dossier.Dossier _Dossier;
    public DTO.Dossier.Dossier Dossier
    {
        get { return _Dossier; }
        set
        {
            _Dossier = value;
            RaisePropertyChanged("Dossier");
        }
    }

    private string _tabName;
    public string TabName
    {
        get { return _tabName; }
        set
        {
            _tabName = value;
            RaisePropertyChanged("TabName");
        }
    }
And the registration of the "SetDossier" Messenger which fills the selected listviewitem to the property "Dossier":
    public DossierDetailViewModel()
    {
        Messenger.Default.Register<DTO.Dossier.Dossier>(this, "SetDossier", (dossier) =>
                                           SetDossier(dossier)
                                             );
    }
Just to be complete, here is my viewmodellocator (only with the code needed for this problem):
    public ViewModelLocator()
    {
        ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

        //Views
        SimpleIoc.Default.Register<DossierDetailViewModel>();

    }

    public DossierDetailViewModel DossierDetail
    {
        get
        {
            return SimpleIoc.Default.GetInstance<DossierDetailViewModel>(Guid.NewGuid().ToString());
        }
    }

Thank you

New Post: Multiple instances of viewmodel

$
0
0
Hi,

Yes there is a flaw in your understanding of what is happening at the XAML level.

in XAML, the DataContext is inherited down to the element's children. This is why, when you have (for instance) a Windows with the DataContext set, you can go to a TextBlock in this window and set Text="{Binding MyProperty}". This will automatically refer to the MyProperty on the current DataContext.

There are two kinds of viewmodels in an application. Some are larger, long lived VMs. For instance MainViewModel, SettingsViewModel, etc. These are suitable for creation and lifetime management in the ViewModelLocator (VML).

But there are also some VMs that are more transient, shorter lived, and these should probably not appear as properties in the VML. Your data items are this kind of VMs. There are typically multiple instances of these smaller, shorter lived VMs. I call them data VMs.

In your case, your tab control's source is an ObservableCollection. Thanks to the CollectionChanged even, your UI will auto update. And thanks to the DataTemplate, the DataContext will automatically be set to the current item of the ObsCollection. This is a cool feature because you don't need to set the DataContext explicitly on the DataTemplate! In fact in most cases it is (as you found out here) impossible to set the DataContext explicity, because you don't know how to identify the right item in the collection.

So in your case, what you need to do is this:
  • Remove the property in the VML. It is useless there because if doesn't provide you the right item for the current UserCOntrol.
  • Remove the DataContext assignment in the XAML. Instead, you will simply inherit the DataContext from the usercontrol's parent, which is the DataTemplate
  • If you need design time features (in Blend or in Visual Studio), you can use the d:DataContext (design time DataContext). Check my MSDN article here: http://msdn.microsoft.com/en-us/magazine/dn169081.aspx
Then the usercontrol's DataContext will automatically be set to the ObservableCollection's item, which is the current instance of the DossierDetailViewModel.

Hopefully this helps.

Cheers
Laurent

New Post: Multiple instances of viewmodel

$
0
0
Yes ! Spot on..thank you for your brief explanation about the XAML DataContext and escpecially about the 2 kinds of viewmodels. I thought all viewmodels had to be put in the viewmodellocator. Thanks to your info I see the difference now between the 2!

Ok so I removed the property from the VML and removed the DataContext assignment as it is inherited by the parent (DataTemplate).

I had to do one more thing which is normal. I removed the Messenger register and send which filled the Dossier property. Because all usercontrols where registered to the same Messenger, the Dossier property always got the last one.

Thank you for your time as your time probably is very valuable to you. I hope someday I could do the same for you ;-)

Serge
Viewing all 1826 articles
Browse latest View live


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