我正在构建Windows Phone应用程序,我正在尝试将我的应用程序连接到twitter。我已经设置了一个页面,要求用户授权应用程序使用他们的Twitter帐户。但是每当我尝试运行我的程序时,我都会收到以下错误:
错误1在类'TheSocialHub.TwitterSetup'上找不到事件处理程序'loginBrowserControl_Navigated'C:\ Users \ charlie stuart \ Desktop \ Windows Phone Project \ TheSocialHub \ TheSocialHub \ TwitterSetup.xaml TheSocialHub
以下是我正在使用的代码,
XAML:
<phone:PhoneApplicationPage
x:Class="TheSocialHub.TwitterSetup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="Sample twitter app" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="main page" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="TweetPanel" Grid.Row="0" Visibility="Collapsed">
<TextBlock x:Name="txtUserName" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="26" FontFamily="Segoe WP Bold" Foreground="Red"/>
</Grid>
<phone:WebBrowser HorizontalAlignment="Left" Margin="10,10,0,0" Name="LoginBrowserControl" VerticalAlignment="Top" Height="473" Width="436" Visibility="Collapsed"
Navigated="loginBrowserControl_Navigated" Navigating="loginBrowserControl_Navigating"/>
</Grid>
</Grid>
<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->
页面的VB.NET代码:
Imports Hammock.Web
Imports System.IO
Imports Hammock
Imports System.Text
Imports Hammock.Authentication.OAuth
Partial Public Class TwitterSetup
Inherits PhoneApplicationPage
Dim OAuthTokenKey As String = String.Empty
Dim tokenSecret As String = String.Empty
Dim accessToken As String = String.Empty
Dim accessTokenSecret As String = String.Empty
Dim userID As String = String.Empty
Dim userScreenName As String = String.Empty
Public Sub New()
InitializeComponent()
If isAlreadyLoggedIn() Then
userLoggedIn()
End If
End Sub
Private Function isAlreadyLoggedIn() As [Boolean]
accessToken = MainUtil.MainUtil.GetKeyValue(Of String)("AccessToken")
accessTokenSecret = MainUtil.MainUtil.GetKeyValue(Of String)("AccessTokenSecret")
userScreenName = MainUtil.MainUtil.GetKeyValue(Of String)("ScreenName")
If String.IsNullOrEmpty(accessToken) OrElse String.IsNullOrEmpty(accessTokenSecret) Then
Return False
Else
Return True
End If
End Function
Private Sub userLoggedIn() Handles loginBrowserControl.Navigated, loginBrowserControl.Navigating
Dispatcher.BeginInvoke(Function()
Dim SignInMenuItem = DirectCast(Me.ApplicationBar.MenuItems(0), Microsoft.Phone.Shell.ApplicationBarMenuItem)
SignInMenuItem.IsEnabled = False
Dim SignOutMenuItem = DirectCast(Me.ApplicationBar.MenuItems(1), Microsoft.Phone.Shell.ApplicationBarMenuItem)
SignOutMenuItem.IsEnabled = True
TweetPanel.Visibility = System.Windows.Visibility.Visible
txtUserName.Text = "Welcome " & userScreenName
End Function)
End Sub
End Class
答案 0 :(得分:1)
您缺少VB.NET代码文件中的事件声明
只需在代码中添加这些声明并检查
即可Private Sub loginBrowserControl_Navigating(sender As Object, e As NavigatingEventArgs)
End Sub
Private Sub loginBrowserControl_Navigated(sender As Object, e As NavigationEventArgs)
End Sub