开发者

Pass data between WPF windows

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

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

Nick


I had a similar problem and discovered that you must create a public property in the MainWindow and pass a value to the property.

Please see this example from a similar question I posted.


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.

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    

Now at the time of assigning a value:
cls_pass_val.Pass_val='A'

and at the time of retrieving the value:

Dim var_c as Char
var_c=cls_pass_val.Pass_val
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜