© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•13mo ago•
7 replies
wildREA

How to Correctly Reference a Method in App.xaml.cs

Hey, reviewer. The
ChangeLanguage
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?)
'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
OnLanguageChanged
method works until I add that reference for
((App)Application.Current)...
((App)Application.Current)...
.

How do I correctly reference to a method in App.xaml.cs?

----

Settings.xaml.cs

    public partial class Settings : UserControl
    {
        public Settings()
        {
            InitializeComponent();
        }

        private void OnLanguageChanged(object sender, SelectionChangedEventArgs e)
        {
            string? selectedLanguage = ((ComboBoxItem?)e.AddedItems[0]).Tag.ToString();
            Debug.WriteLine(selectedLanguage);
            ((App)Application.Current).ChangeLanguage(selectedLanguage);
        }
    }
}
    public partial class Settings : UserControl
    {
        public Settings()
        {
            InitializeComponent();
        }

        private void OnLanguageChanged(object sender, SelectionChangedEventArgs e)
        {
            string? selectedLanguage = ((ComboBoxItem?)e.AddedItems[0]).Tag.ToString();
            Debug.WriteLine(selectedLanguage);
            ((App)Application.Current).ChangeLanguage(selectedLanguage);
        }
    }
}


App.xaml.cs

public partial class App : Application
{
    public void ChangeLanguage(string language)
    {
public partial class App : Application
{
    public void ChangeLanguage(string language)
    {
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Manually Showing MainWindow.xaml In App.xaml.cs (Dependency Injection)
C#CC# / help
13mo ago
error CS1061, error CS0105, CS0103
C#CC# / help
2y ago
App.xaml
C#CC# / help
17mo ago
✅ How to use ResourceDictionary in the App.xaml?
C#CC# / help
8mo ago