繁体   English   中英

Windows Phone 7错误

[英]windows phone 7 errors

http://i.stack.imgur.com/ZxpaP.png

未声明“ InitializeComponent”。 由于其保护级别,它可能无法访问。

http://i.stack.imgur.com/na20Z.png

'CountTextBlock'不是'Tally.Tally.MainPage'的成员。

我不知道为什么我会收到这些错误。 请检查链接以获取错误图片。 我已经使用许多转换器将代码从c#转换为Vb.net。 它们都给出相同的转换。

代码:-

Imports System.Windows
Imports System.Windows.Input
Imports System.Windows.Navigation
Imports Microsoft.Phone.Controls
Imports Tally.WindowsPhoneApp ' For the Setting class



Namespace Tally
    Partial Public Class MainPage
        Inherits PhoneApplicationPage
        Private count As Integer = 0
        ' Remember what the user typed, for future app activations or launches:
        Private savedCount As New Setting(Of Integer)("SavedCount", 0)

        Public Sub New()
            InitializeComponent()
        End Sub

        ' Handle a tap anywhere on the page (other than the Button)
        Protected Overrides Sub OnMouseLeftButtonDown(ByVal e As MouseButtonEventArgs)
            MyBase.OnMouseLeftButtonDown(e)
            Me.count += 1
            Me.CountTextBlock.Text = Me.count.ToString("N0")
        End Sub

        ' Handle a tap on the button
        Private Sub ResetButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.count = 0
            Me.CountTextBlock.Text = Me.count.ToString("N0")
        End Sub

        Protected Overrides Sub OnNavigatedFrom(ByVal e As NavigationEventArgs)
            MyBase.OnNavigatedFrom(e)
            ' Persist state when leaving for any reason (Deactivated or Closing):
            Me.savedCount.Value = Me.count
        End Sub

        Protected Overrides Sub OnNavigatedTo(ByVal e As NavigationEventArgs)
            MyBase.OnNavigatedTo(e)
            ' Restore persisted state:
            Me.count = Me.savedCount.Value
            Me.CountTextBlock.Text = Me.count.ToString("N0")
        End Sub
    End Class
End Namespace

Settings.vb

Imports System.IO.IsolatedStorage
Namespace WindowsPhoneApp
    ' Encapsulates a key/value pair stored in Isolated Storage ApplicationSettings
    Public Class Setting(Of T)
        Private name As String
        'INSTANT VB NOTE: The variable value was renamed since Visual Basic does not allow class members with the same name:
        Private value_Renamed As T
        'INSTANT VB NOTE: The variable defaultValue was renamed since Visual Basic does not allow class members with the same name:
        Private defaultValue_Renamed As T
        Private hasValue As Boolean
        Public Sub New(ByVal name As String, ByVal defaultValue As T)
            Me.name = name
            Me.defaultValue_Renamed = defaultValue
        End Sub
        Public Property Value() As T
            Get
                ' Check for the cached value
                If Not Me.hasValue Then
                    ' Try to get the value from Isolated Storage
                    If Not IsolatedStorageSettings.ApplicationSettings.TryGetValue(Me.name, Me.value_Renamed) Then
                        ' It hasn’t been set yet
                        Me.value_Renamed = Me.defaultValue_Renamed
                        IsolatedStorageSettings.ApplicationSettings(Me.name) = Me.value_Renamed
                    End If
                    Me.hasValue = True
                End If

                Return Me.value_Renamed
            End Get
            Set(ByVal value As T)
                ' Save the value to Isolated Storage
                IsolatedStorageSettings.ApplicationSettings(Me.name) = value
                Me.value_Renamed = value
                Me.hasValue = True
            End Set
        End Property
        Public ReadOnly Property DefaultValue() As T
            Get
                Return Me.defaultValue_Renamed
            End Get
        End Property
        ' "Clear" cached value:
        Public Sub ForceRefresh()
            Me.hasValue = False
        End Sub
    End Class
End Namespace

尝试首先通过内置的Visual Studio工具在项目中创建新页面,然后将翻译后的代码复制并粘贴到自动生成的代码之上。

我认为问题在于,您缺少手动创建这些页面时通常自动生成的其余.designer.vb代码文件。

我没有做过任何VB编程,但仅出于这个问题,我决定尝试一下。 正如@Merlyn所说,如果只使用Visual Studio模板来开发应用程序,那应该没问题。 我用VB的基本Windows Phone应用程序项目模板创建了我的。 它的工作方式类似于C#中的工作方式。 InitializeComponent()是在.xaml文件(在本例中为mainpage.xaml)的关联.g.vb中定义的公共方法。 为了查看其中包含的内容,只需在构造函数后面的mainPage代码中的InitializeComponent调用上进行定义 这就是基本定义所包含的内容。 该例程中的代码知道如何将您在xaml中定义的控件加载到相应的.NET Framework对象中。

 Public Sub InitializeComponent()
        If _contentLoaded Then
            Return
        End If
        _contentLoaded = true
        System.Windows.Application.LoadComponent(Me, New System.Uri("/PhoneApp1;component/MainPage.xaml", System.UriKind.Relative))
        Me.LayoutRoot = CType(Me.FindName("LayoutRoot"),System.Windows.Controls.Grid)
        Me.TitlePanel = CType(Me.FindName("TitlePanel"),System.Windows.Controls.StackPanel)
        Me.ApplicationTitle = CType(Me.FindName("ApplicationTitle"),System.Windows.Controls.TextBlock)
        Me.PageTitle = CType(Me.FindName("PageTitle"),System.Windows.Controls.TextBlock)
        Me.ContentPanel = CType(Me.FindName("ContentPanel"),System.Windows.Controls.Grid)
    End Sub

如果要查找此文件,则位于obj / Data / MainPage.givb中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM