我想分享至少两个WPF窗口之间下面的类之间的类:共享两个WPF窗口
namespace WPF
{
class dd_internals
{
public int current_process_index;
public class process_class
{
public string process_name;
public List<string> parm_list;
public List<string> var_list;
public List<string> statements;
}
public List<process_class> process_list = new List<process_class>();
}
}
我将如何共享多个窗口之间这个类的一个实例?
确定代码显示dd_internals
被传入构造函数window1
,但不能直接在window1
的成员函数中使用。
namespace posting2
{
public partial class Window1 : Window
{
public void Member()
{
int y = Data.current_process_index;
// Error: the name 'Data' does not exist in the current context
}
public Window1(dd_internals data)
{
int x = data.current_process_index;
// ok, it works here.
InitializeComponent();
}
}
}
没有足够的信息来真正告诉,但可能https://en.wikipedia.org/wiki/Singleton_pattern? –
请解释“共享一个实例”的含义。一个你认为能做什么好的例子会有帮助。 –
共享一个实例:这意味着有一个类x,两个窗口都会更新它,并且更新显示在它访问的任何位置。在C++中,一个模块可能定义类x,而其他所有模块都可以访问类ref *,其中ref =&x。 – quincy451