Windows Phone 7 convenient notepad instance

Source: Internet
Author: User

This is a simple notepad. It uses local storage to record your content in real time and exitProgramThe content of the notepad is automatically saved. The following toolbar is used to zoom in or out the font.

The custom quicknotessettings class is used to save the content and font size of the notepad. It also encapsulates the loading and saving methods of the notepad.

 Using  System;
Using System. Io. isolatedstorage;
Using System. windows;

Namespace Quicknotes
{
Public Class Quicknotessettings
{
Public Quicknotessettings ()
{
This . Text = "" ;
This . Fontsize = ( Double ) Application. Current. Resources [ " Phonefontsizemediumlarge " ];
}

Public String Text { Set ; Get ;}
Public Double Fontsize { Set ; Get ;}
// Obtain the content of the local notepad through static methods
Public Static Quicknotessetaskload ()
{
Isolatedstorageset=isosettings = Isolatedstoragesettings. applicationsettings;
Quicknotessetasksettings;

If ( ! Isosettings. trygetvalue < Quicknotessettings > ( " Settings " , Out Settings ))
Settings = New Quicknotessettings ();

Return Settings;
}
// Save to local storage
Public Void Save ()
{
Isolatedstorageset=isosettings = Isolatedstoragesettings. applicationsettings;
Isosettings [ " Settings " ] = This ; // The instance of this class is saved.
}
}
}

XAML files

 <! --  Layoutroot contains the root grid where all other 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 =" >
< Textblock X: Name = "Applicationtitle" Text = "Quick notes" Style =" {Staticresource phonetextnormalstyle} " />
</ Stackpanel >

< Grid X: Name = "Contentpanel" Grid. Row = "1" Margin = "12, 0, 12, 0" >
< Textbox Name = "Txtbox"
Textwrapping = "Wrap"
Acceptsreturn = "True"
Verticalscrollbarvisibility = "Auto"
Textchanged = "Ontextboxtextchanged" />
</ Grid >
</ Grid >

< Phone: phoneapplicationpage. ApplicationBar >
< Shell: ApplicationBar >
<! -- Zoom out -->
< Shell: applicationbariconbutton Iconuri = "/Images/littleletter.icon.png"
Text = "Smaller font"
Click = "Onappbarsmallerfontclick" />
<! -- Zoom in -->
< Shell: applicationbariconbutton Iconuri = "/Images/bigletter.icon.png"
Text = "Larger font"
Click = "Onappbarlargerfontclick" />
</ Shell: ApplicationBar >
</ Phone: phoneapplicationpage. ApplicationBar >

Corresponding CS Background File

 Using  System;
Using System. windows;
Using System. Windows. controls;
Using Microsoft. Phone. controls;

Namespace Quicknotes
{
Public Partial Class Mainpage: phoneapplicationpage
{
Quicknotessettings appsettings = (Application. Current As APP). deleettings;

Public Mainpage ()
{
Initializecomponent ();

Txtbox. Text = Etettings. text;
Txtbox. fontsize = Appsettings. fontsize;
}
// Save the content of notepad to local storage.
Void Ontextboxtextchanged ( Object Sender, textchangedeventargs ARGs)
{
Appsettings. Text = Txtbox. text;
}
// Shrink font
Void Onappbarsmallerfontclick ( Object Sender, eventargs ARGs)
{
Txtbox. fontsize = Math. Max ( 12 , Txtbox. fontsize - 1 );
Appsettings. fontsize = Txtbox. fontsize;
}
// Font Extension
Void Onappbarlargerfontclick ( Object Sender, eventargs ARGs)
{
Txtbox. fontsize = Math. Min ( 48 , Txtbox. fontsize + 2 );
Appsettings. fontsize = Txtbox. fontsize;
}
}
}

App. XAML. CS main program File Modification

 ......
Public Quicknotessettings appsettings { Set ; Get ;}
Public Phoneapplicationframe rootframe { Get ; Private Set ;}

Public APP ()
{

Unhandledexception + = Application_unhandledexception;
Initializecomponent ();
Initializephoneapplication ();
}

Private Void Application_launching ( Object Sender, launchingeventargs E)
{
Appsettings = Quicknotessettings. Load ();
}

Private Void Application_activated ( Object Sender, activatedeventargs E)
{
Appsettings = Quicknotessettings. Load ();
}

Private Void Application_deactivated ( Object Sender, deactivatedeventargs E)
{
Deleetask. save ();
}

Private Void Application_closing ( Object Sender, closingeventargs E)
{
Deleetask. save ();
}
......
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.