建体彩网|中彩网双色球连号|
?
快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

亞博國際誤樂:Windows Phone 7 獨立存儲使用XML文件來存儲信息

?

XML布局清晰,應用手機自力存儲的時刻可以使用上XML的文件布局來保存信息,這是一種不錯的選擇。

應用IsolatedStorageFile工具來實現手機信息的存儲,有三個主要步驟,

1、調用手機的自力存儲

IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()

2、創建自力存儲文件流

IsolatedStorageFileStream location = new IsolatedStorageFileS亞博國際誤樂tream(nameTxt.Text + ".item", System.IO.FileMode.Create, storage);

3、讀寫該文件流

寫:

//將本地存儲文件流轉化為可寫流

System.IO.StreamWriter file = new System.IO.StreamWriter(location);

//將XML文件 保存到流file上 即已經寫入得手機本地存儲文件上

_doc.Save(file);//_doc是你創建的文件

讀:

//轉化為可讀流

System.IO.StreamReader file = new System.IO.StreamReader(location);

//解析流 轉化為XML

_xml = XElement.Parse(file.ReadToEnd());

下面是一個Demo購物清單

清單列表

MainPage.xaml

phone:PhoneApplicationPage

x:Class="ShoppingList_Demo.MainPage"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"

xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

FontFamily="{StaticResource PhoneFontFamilyNormal}"

FontSize="{StaticResource PhoneFontSizeNormal}"

Foreground="{StaticResource PhoneForegroundBrush}"

SupportedOrientations="Portrait" Orientation="Portrait"

mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"

shell:SystemTray.IsVisible="True">

phone:PhoneApplicationPage.ApplicationBar>

shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">

shell:ApplicationBar.MenuItems>

shell:ApplicationBarMenuItem Text="新增" Click="New_Click"/>

shell:ApplicationBar.MenuItems>

shell:ApplicationBar>

phone:PhoneApplicationPage.ApplicationBar>

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="24,24,0,12">

TextBlock x:Name="PageTitle" Text="購物清單" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>

StackPanel>

ContentPanel - place additional content here-->

Grid x:Name="ContentGrid" Grid.Row="1">

ListBox Grid.Row="0" Margin="10" FontSize="48" Name="Files">

ListBox>

Grid>

Grid>

phone:PhoneApplicationPage>

AddItem.xaml

phone:PhoneApplicationPage

x:Class="ShoppingList_Demo.AddItem"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"

xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"

xmlns:d="http://schemas.microsoft.com/亞博國際誤樂expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

FontFamily="{StaticResource PhoneFontFamilyNormal}"

FontSize="{StaticResource PhoneFontSizeNormal}"

Foreground="{StaticResource PhoneForegroundBrush}"

SupportedOrientations="Portrait" Orientation="Portrait"

mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"

shell:SystemTray.IsVisible="True">

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="24,24,0,12">

TextBlock x:Name="PageTitle" Text="添加商品" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>

StackPanel>

ContentPanel - place additional content here-->

Grid x:Name="ContentGrid" Grid.Row="1">

Grid.RowDefiniti亞博國際誤樂ons>

RowDefinition Height="90" MinHeight="72.5"/>

RowDefinition Height="90" MinHeight="72.5"/>

RowDefinition Height="90" MinHeight="72.5"/>

RowDefinition />

Grid.RowDefinitions>

Grid.ColumnDefinitions>

ColumnDefinition Width="100*" />

ColumnDefinition Width="346*"/>

Grid.ColumnDefinitions>

TextBlock Grid.Column="0" Grid.Row="0" Text="名稱:" HorizontalAlignment="Center" VerticalAlignment="Center" />

TextBox Name="nameTxt"Grid.Column="1" Margin="8,8,8,0" Padding="2" />

TextBlock Grid.Column="0" Grid.Row="1" Text="價格:"HorizontalAlignment="Center" VerticalAlignment="Center" />

TextBox x:Name="priceTxt"Grid.Column="1" Margin="8,8,8,0" Padding="2" Grid.Row="1"/>

TextBlock Grid.Column="0" Grid.Row="2" Text="數量:" HorizontalAlignment="Center" VerticalAlignment="Center" />

TextBox Name="quanTxt" Grid.Column="1" Margin="8,8,8,375" Padding="2" Grid.Row="2" Grid.RowSpan="2" />

Grid>

Button x:Name="BtnSave" Content="保存" HorizontalAlignment="Right" Margin="0,0,17,0" Grid.Row="1" VerticalAlignment="Bottom" Click="BtnSave_Click" />

Grid>

phone:PhoneApplicationPage>

查看商品具體

DisplayPage.xaml

phone:PhoneApplicationPage

x:Class="ShoppingList_Demo.DisplayPage"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"

xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

FontFamily="{StaticResource PhoneFontFamilyNormal}"

FontSize="{StaticResource PhoneFontSizeNormal}"

Foreground="{StaticResource PhoneForegroundBrush}"

SupportedOrientations="Portrait" Orientation="Portrait"

mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"

shell:SystemTray.IsVisible="True">

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="24,24,0,12">

TextBlock x:Name="PageTitle" Text="商品信息" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>

StackPanel>

ContentPanel - place additional content here-->

Grid x:Name="ContentGrid" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Center" Margin="10,10,10,77" ShowGridLines="True" Width="446" d:LayoutOverrides="GridBox">

Grid.RowDefinitions>

RowDefinition Height="Auto" MinHeight="72.5"/>

RowDefinition Height="Auto" MinHeight="72.5"/>

RowDefinition Height="Auto" MinHeight="72.5"/>

RowDefinition />

Grid.RowDefinitions>

Grid.ColumnDefinitions>

ColumnDefinition Width="0.3*" />

ColumnDefinition Width="*"/>

Grid.ColumnDefinitions>

TextBlock Grid.Column="0" Grid.Row="0" Text="名稱:" HorizontalAlignment="Center" VerticalAlignment="Center" />

TextBlock Name="nameTxt"Grid.C亞博國際誤樂olumn="1" Margin="8" Padding="2" Height="59"/>

TextBlock Grid.Row="1" Text="價格:" HorizontalAlignment="Center" VerticalAlignment="Center" />

TextBlock x:Name="priceTxt"Grid.Column="1" Margin="8" Padding="2" Height="59" Grid.Row="1"/>

TextBlock Grid.Column="0" Grid.Row="2" Text="數量:" HorizontalAlignment="Center" VerticalAlignment="Center" />

TextBlock Name="quanTxt" Grid.Column="1" Margin="8" Padding="2" Height="59" Grid.Row="2" />

Grid>

Button x:Name="BtnBack" Content="回到購物清單" HorizontalAlignment="Right" Margin="0,0,17,0" Grid.Ro亞博國際誤樂w="1" VerticalAlignment="Bottom" Click="BtnBack_Click" />

Grid>

phone:PhoneApplicationPage>

免責聲明:以上內容源自網絡,版權歸原作者所有,如有侵犯您的原創版權請告知,我們將盡快刪除相關內容。

您可能還會對下面的文章感興趣:

建体彩网
百度彩票 地下城勇士游戏 福彩组选中奖多少 电子游艺300元体验金可提款 幸运赛车 京东新11选5走势图 十一运夺金预测 飞镖职业选手收入 三码中特公式规律 辽宁十一选五连线走势图