C#C
C#11mo ago
wildREA

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

    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)
    {
Was this page helpful?