[英]How do I reference the properties of a control from another class?
Public Class Form1
Private Sub FormLoad(sender As Object, e As EventArgs) Handles MyBase.Load
Dim myClosed As Integer = 0
Dim myProgress As Integer = 0
Dim myReview As Integer = 0
Dim myRejected As Integer = 0
Dim myCompleted As Integer = 0
Dim myImplemented As Integer = 0
For Each item In MainWindow.DatabaseList.Items
If item.Status = "Closed" Then
myClosed += 1
End If
If item.Status = "In Progress" Then
myProgress += 1
End If
If item.Status = "In Review" Then
myReview += 1
End If
If item.Status = "Rejected" Then
myRejected += 1
End If
If item.Status = "Completed" Then
myCompleted += 1
End If
If item.Status = "Implemented" Then
myImplemented += 1
End If
Next
ClosedNr.Text = myClosed
ProgressNr.Text = myProgress
ReviewNr.Text = myReview
RejectedNr.Text = myRejected
CompletedNr.Text = myCompleted
ImplementedNr.Text = myImplemented
End Sub
End Class
当我尝试引用 MainWindow class 时出现此错误。
Error BC30469 Reference to a non-shared member requires an object reference.
我尝试将 MainWindow FieldModifier 设置为 public,但它不能修复错误。
我也试过:
Dim myMainWindow as MainWindow = New MainWindow
但是这样做时,我的 DatabaseList.Items.Count 返回 0。
项目是 VB.Net,但标记为 C# 因为我也可以在 C# 中编码。
To get the ItemCollection from a WPF Window Class delivered to your WF Window Class you have to do the following:
在您的 WF Window Class 中声明一个新事件,如下所示:
Public Sub New(ByVal items As ItemCollection)
结束子
Go to the event in your WPF Window class that manages the WF Window Class and add the argument like this:
Private Sub Dashboard_Click(发件人为 Object,e 为 RoutedEventArgs)
Dim myWindow As Form1 = New Form1(DatabaseList.Items) myWindow.Show() End Sub
然后,您可以通过简单的方式访问 ItemCollection:
For Each item As myRow In items
Next
感谢 Charles 和 zaggler 找到了解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.