-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use from ViewModels not having a dependency on MAUI? #22
Comments
@SirJohnK would be curious to hear your thoughts on this! Am happy to create a PR that extracts the interfaces into a |
@hansmbakker , I like the idea to extract the Solution:
I will look into this tonight. 😄 |
@hansmbakker , I think I have found a really nice solution for this! 😄
So now you can do this ViewModel with only help from MVVM Community Toolkit: using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using LocalizationResourceManager.Maui.Core;
namespace LocalizationResourceManager.Maui.Sample.Common;
public partial class MainViewModel : ObservableObject
{
public LocalizedString HelloWorld { get; }
public LocalizedString CurrentCulture { get; }
public MainViewModel(ILocalizationResourceManager resourceManager)
{
//Init
HelloWorld = resourceManager.CreateLocalizedString(() => $"{resourceManager["Hello"]}, {resourceManager["World"]}!");
CurrentCulture = new(resourceManager, () => resourceManager.CurrentCulture.NativeName);
}
[ObservableProperty]
private int count;
[RelayCommand]
private void CounterClicked() => Count++;
} What do you think? |
That looks good! Great! |
@hansmbakker, if you have the time, please test it out and report back your findings. Would be great to have some feedback before I will go live with this version! |
I have my solution split in several projects where my project containing a ViewModels does not have a dependency on MAUI - just on the MVVM Community Toolkit.
Is there a way to access the
ILocalizationResourceManager
from ViewModels without taking a dependency on MAUI viaLocalizationResourceManager.Maui
?E.g. in this example app, the MAUI dependent parts of localization and the view-agnostic parts of localization are put in separate projects so that the ViewModels can reference just the interface.
I see I could create a kind of wrapper pair (interface + implementation) myself, but it would be great to have this in the library!
The text was updated successfully, but these errors were encountered: