使用全局变量WPF应用程序 [英] WPF Application using a global variable

查看:2542
本文介绍了使用全局变量WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了C#与3个不同的窗口,Home.xaml,Name.xaml,Config.xaml WPF应用程序。我想声明的Home.xaml.cs一个变量,我可以同时在其他形式使用。我试着做公共字符串重量=;但没有奏效。我怎样才能使它可用所有三种形式?

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 can use in both the other forms. I tried doing public string wt = ""; but that didn't work. How can I make it usable by all three forms?

推荐答案

正确的方法,特别是如果你想要移动到XBAPP,是将其存储在

The proper way, especially if you ever want to move to XBAPP, is to store it in

Application.Current.Properties

这是一个字典对象。

这篇关于使用全局变量WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆