WPF Application using a global variable

前端 未结 6 2025
余生分开走
余生分开走 2020-12-08 11:10

I created a WPF application in c# with 3 different windows, Home.xaml, Name.xaml, Config.xaml. I want to declare a variable in Home.xaml.cs that I

6条回答
  •  失恋的感觉
    2020-12-08 11:39

    You can use a static property:

    public static class ConfigClass()
    {
        public static int MyProperty { get; set; }
    }
    

    Edit:

    The idea here is create a class that you holds all "common data", typically configurations. Of course, you can use any class but suggest you to use a static class. You can access this property like this:

    Console.Write(ConfigClass.MyProperty)
    

提交回复
热议问题