[英]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.