In this tutorial we are going to cover the basics required to set up an IsolatedStorage object and use it to store information from our Statistics Tracker.  For the interface to use the isolated storage we are going to reuse our Graphical User Interface (GUI) from the previous tutorial and build upon it and add a couple of items to help with visualizing the data entered. First, we will learn what isolated storage is and how it will affect you in programming for the Windows Phone 7 environment.  Isolated Storage for the Windows Phone 7 is similar to Silverlight’s Isolated Storage but with one key difference.  The difference being there is  no function to set a quota for how much memory the application can take to store the data it saves.  Other than this small difference isolated storage is the storage that an application can use to store data, while that particular application is the only one with access to that data.

Now that we know what isolated storage is we can begin preparations for when we are going to use it.  To do so we need to modify the GUI of our previous statistics tracker.  After you have the previous project open we need to drag another 2 buttons under the submit button and fix them accordingly.  We will change the content of the one on the left to View Results and change the objects name to btnResult and double clicking on the button will create you the event handler we will need later on.  Now if we change the other buttons name to btnDelete and change the content of the button to Delete DB.  After this is done we can double click on this button to create another event handler.  We then need to add a ListBox from the toolbox and drag it under the two buttons and stretch it to the edges of the screen using the visual side of the editor and name it lbEntries. This will accomplish all of the visual aspects that we will need to modify to make the changes to the isolated storage visible.  When the positioning is done the end result should look something like below.

 

 

We can then move on to changing the InputScope of the textbox where our numbers will go. To do this we need to modify the XAML to interpret just numbers. Before we change this, this is what the code looked like before any changes were made.

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock x:Name="NumRewTitle" Text="Number Of Rewards:" Style="{StaticResource PhoneTextNormalStyle}" Margin="0,0,0,578" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="0,22,0,0" Name="txtNumRew" Text="" VerticalAlignment="Top" Width="460" />
<TextBlock x:Name="DateTitle" Text="Date:" Style="{StaticResource PhoneTextNormalStyle}" Margin="0,100,24,479" />
<toolbox:DatePicker x:Name="BirthDate" ValueChanged="BirthDate_ValueChanged" Margin="0,134,0,-134" />

<Button Content="Submit" Click="btnSubmit_Click" Margin="0,210,0,322" Name="btnSubmit" />
<Button Content="View Entries" Click="btnResult_Click" Margin="0,291,229,244" Name="btnResult" />
<ListBox Height="238" HorizontalAlignment="Left" Margin="-4,369,0,0" Name="lbEntries" VerticalAlignment="Top" Width="460" IsEnabled="True" />
<Button Content="Delete DB" Height="72" Margin="224,291,6,0" Name="btnDelete" VerticalAlignment="Top" Click="btnDelete_Click" />
</Grid>

So to be able to omit letters from being chosen we must add InputScope=”TelephoneNumber” to the following line of code and make it look exactly the same, which will allow only numbers and anything related to a telephone keypad will be available to the user.

<TextBox Height="72" HorizontalAlignment="Left" Margin="0,22,0,0" Name="txtNumRew" Text="" VerticalAlignment="Top" Width="460" InputScope="TelephoneNumber" />
Share This