Sunny Bhattacharjee
Sunny Bhattacharjee

Reputation: 107

VB.Net Namespace equivalent to C#

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”);
}
}
}

I am not a C# coder..i use VB.net...anyway i tried converting it using an online conversion tool...but the vb code is full of errors.Can anyone help me with this??I have just started learning Windows Phone 7.

What namespace should be imported in VB for using WindowsPhoneApp;??

Upvotes: 1

Views: 683

Answers (2)

Kevin Gosse
Kevin Gosse

Reputation: 39007

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

The chapter 1 app (like almost every app in the book) uses a Settings class to interact with isolated storage. This way, it can remember values the next time the app runs. In the code download for the book, the project includes the necessary Settings.cs class which makes this error go away. The code for this class is also included in the book in Chapter 20, when the topic of isolated storage is discussed.

So you've got two options:

1.Copy Settings.cs from the Chapter 1 code download and include it in your project.

2.Create a new Settings.cs file in your project and type in the Settings.cs code from Chapter 20. There is a bullet point in Chapter 1 that attempts to explain the situation, but I realize that it is too confusing.

Upvotes: 1

user774411
user774411

Reputation: 1809

Try this online converter

I have tried the converter and this is the converted result:

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

Upvotes: 1

Related Questions