WPF Application using a global variable

前端 未结 6 2037
余生分开走
余生分开走 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:37

    There are two different things you can do here (among others; these are just the two that come to mind first).

    1. You could make the variable static on Home.xaml.cs

      public static string Foo = "";
      
    2. You could just pass in the variable to all three forms.

    I would go with #2, myself, and if necessary create a separate class that contains the data I need. Then each class would have access to the data.

提交回复
热议问题