Imports App1.LoadHandler
Public NotInheritable Class MainPage
Inherits Page
Public Shared mp As New MainPage
Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
lh.Load()
End Sub
End Class
Imports App1.MainPage
Public Class LoadHandler
Public Shared lh As New LoadHandler
Public Sub Load()
AddImageObjectstoList()
End Sub
Private Sub AddImageObjectstoList()
dh.imgdice.Add(imgDice1)
dh.imgdice.Add(imgDice2)
dh.imgdice.Add(imgDice3)
dh.imgdice.Add(imgDice4)
dh.imgdice.Add(imgDice5)
End Sub
End Class
我收到消息“'App1.MainPage.Private WithEvents imgDice1 As Windows.UI.Xaml.Controls.Image'在此上下文中无法访问,因为它是'Private'。”当鼠标悬停在dh.imgdice.Add(imgDice1)上时。
在“AddImageObjectstoList()”中,我无法访问imgDice1 - imgDice5,因为它是私有的。在MainPage.xaml.vb之外访问Windows.UI.Xaml.Controls.Image控件的最佳方法是什么?
答案 0 :(得分:1)
这个问题有点模糊,但我猜你在imgDice1
中声明了imgDice5
- MainPage.xaml
。这些是默认的私有字段。要公开它们,您需要使用x:FieldModifier="public"
:
<Image x:Name="imgDice1" x:FieldModifier="public" />
<Image x:Name="imgDice2" x:FieldModifier="public" />
<Image x:Name="imgDice3" x:FieldModifier="public" />
<Image x:Name="imgDice4" x:FieldModifier="public" />
<Image x:Name="imgDice5" x:FieldModifier="public" />
通过这种方式,您也可以从其他类中访问它们,而不仅仅是从MainPage
内。