How to Correctly Reference a Method in App.xaml.cs
Hey, reviewer. The
ChangeLanguage
method should work, but referencing is a challenge at the moment, since I get the error 'App' does not contain a definition for 'ChangeLanguage' and no accessible extension method 'ChangeLanguage' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?)
.
The OnLanguageChanged
method works until I add that reference for ((App)Application.Current)...
.
How do I correctly reference to a method in App.xaml.cs?
----
Settings.xaml.cs
App.xaml.cs
4 Replies
You can use dependency injection or make the method static if it does not access instance data
I have this and
ServiceProvider
is apparently not defined in App
despite having defined it. I've used using Microsoft.Extensions.DependencyInjection;
.
Settings.xaml.cs
App.xaml.cs
'App' does not contain a definition for 'ServiceProvider'
Check that you're referencing the correct
App
. ServiceProvider
is static and public and it must be there.
Although the best practice for a service locator class is for it to be encapsulated
So create a static method that fetches the service
Don't expose the actual ServiceProvider
@Nasdack I'll try it on Monday at 8.