2011-12-10 62 views
1
using System.Windows; 
using System.Windows.Input; 
using System.Windows.Navigation; 
using Microsoft.Phone.Controls; 
using WindowsPhoneApp; // For the Setting class 
namespace Tally 
{ 
public partial class MainPage : PhoneApplicationPage 
{ 
int count = 0; 
// Remember what the user typed, for future app activations or launches 
Setting<int> savedCount = new Setting<int>(“SavedCount”, 0); 
public MainPage() 
{ 
InitializeComponent(); 
} 
// Handle a tap anywhere on the page (other than the Button) 
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) 
{ 
base.OnMouseLeftButtonDown(e); 
this.count++; 
this.CountTextBlock.Text = this.count.ToString(“N0”); 
} 
// Handle a tap on the button 
void ResetButton_Click(object sender, RoutedEventArgs e) 
{ 
this.count = 0; 
this.CountTextBlock.Text = this.count.ToString(“N0”); 
} 
protected override void OnNavigatedFrom(NavigationEventArgs e) 
{ 
base.OnNavigatedFrom(e); 
// Persist state when leaving for any reason (Deactivated or Closing) 
this.savedCount.Value = this.count; 
} 
protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
base.OnNavigatedTo(e); 
// Restore persisted state 
this.count = this.savedCount.Value; 
this.CountTextBlock.Text = this.count.ToString(“N0”); 
} 
} 
} 

我不是C#编码器..我使用VB.net ...无论如何,我尝试使用在线转换工具将其转换...但vb代码充满了错误。任何人都可以帮助我呢?我刚开始学习Windows Phone 7.VB.Net命名空间等效于C#

什么名字空间应该在VB中导入using WindowsPhoneApp; ??

+0

WindowsPhoneApp命名空间在C#中不存在。你在哪里找到这个代码?你可能错过了一些东西。 –

回答

1

http://forums.create.msdn.com/forums/p/82711/514488.aspx

第1章应用程序(如几乎每一个在这本书的应用程序)使用Settings类与独立存储进行交互。这样,它可以在下次运行应用程序时记住值。在本书的代码下载中,该项目包含必要的Settings.cs类,这个错误消失了。当讨论隔离存储的话题时,这个类的代码也包含在第20章的书中。从第1章代码下载

1.复印Settings.cs,包括在您的项目:

所以,你有两个选择。

2.在您的项目中创建一个新的Settings.cs文件并键入第20章的Settings.cs代码。 第1章中有一个要点试图解释这种情况,但我意识到它是太混乱了。

1

试试这个在线converter

我试图转换器,这是转换结果:

Imports System.Windows 
Imports System.Windows.Input 
Imports System.Windows.Navigation 
Imports Microsoft.Phone.Controls 
Imports WindowsPhoneApp 
' For the Setting class 
Namespace Tally 
    Public Partial 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(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(sender As Object, e As RoutedEventArgs) 
      Me.count = 0 
      Me.CountTextBlock.Text = Me.count.ToString(N0) 
     End Sub 
     Protected Overrides Sub OnNavigatedFrom(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(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