在 WPF 窗口之间传递数据 [英] Pass data between WPF windows
问题描述
我有一些代码可以在 winforms 中运行,但显然不能在 WPF 中运行,代码如下:这是全局设置的:
I have some code that works in winforms, but not in WPF apparently, the code is as follows: This is set globally:
Private Property avar As Object
Public main As MainWindow
Public charchoice As Char
然后在Window Loaded子中,放置:
And then in the Window Loaded sub, this is placed:
charchoice = main.charchoice
问题是,下一个窗口没有选择这个变量,那么我怎样才能让它识别和使用它呢?谢谢各位
Thing is, the next window doesn't pick up this variable, so how can I make it recognise and use it? Thanks Guys
尼克
推荐答案
嘿,我在两个表单之间传递值时遇到了同样的问题.我使用一个简单的类和 Shared 属性找到了它的解决方案.
Hey i got same problem when i am going to pass values between two forms. I find its solution using a simple class and Shared property.
首先我创建一个名为 cls_pass_val 的类,如下所示:-
First I create a class named with cls_pass_val which is as under:-
Public Class cls_pass_val
Private Shared var_pass_val As String = ""
Public Shared Property Pass_val() As Char
Get
Return var_pass_val
End Get
Set(ByVal value As String)
var_pass_val = value
End Set
End Property
End Class
现在在赋值时:cls_pass_val.Pass_val='A
'
并在检索值时:
Dim var_c as Char
var_c=cls_pass_val.Pass_val
这篇关于在 WPF 窗口之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!