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中为using WindowsPhoneApp;
??
答案 0 :(得分: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
答案 1 :(得分: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章中有一个要点试图解释这种情况,但我意识到它太混乱了。