Reputation: 1477
I'm working on a cross platform app using Xamarin forms in VS 2017, employing the I18n-portable NuGet-Package for internationalization (see http://xleon.net/localization/xamarin/pcl/share-locales/i18n/portable/dotnet/2017/02/09/easy-and-cross-platform-localization-for-xamarin-and-dotnet/). I got everything working so far, except for one thing.
Unfortunately, I am stuck on the last part where - according to the package readme - I need to create a proxy object on the baseviewmodel. I just don't know what to do here and no documentation on the web seems to help me with that.
What/where is the baseviewmodel?! Is it in App.xaml.cs
of my example PCL solution? This is the code that the author of the package proposes to integrate:
public abstract class BaseViewModel
{
public I18N Strings => I18N.Current; // causes error, see below
}
The code above causes an error when trying to integrate it as a new class:
Error CS0266: The type "I18NPortable.II18N" can't be implictly converted to "I18NPortable.I18N". There already exists an explicit conversion (conversion missing?).
Thanks for every hint.
Upvotes: 0
Views: 236
Reputation: 2981
For the BaseViewModel
you will need to use an MVVM framework which is dependent on ViewModels. You then create a custom base class that your other view models inherit from which implements this. It is not something Xamarin hands you out of the box as MVVM is not a must when using Xamarin Forms and there are a number of MVVM frameworks out there.
The error you're getting basically says that the call to I18N.Current
returns an object of type II18N which is an interface that you're assigning to an explicit type. You could try changing it to:
public abstract class BaseViewModel
{
public II18N Strings => I18N.Current;
}
Upvotes: 0