<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zdave Blog</title>
	<atom:link href="http://www.zdave.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zdave.net</link>
	<description>Farewell</description>
	<lastBuildDate>Wed, 14 Sep 2011 02:03:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>你选择了你的路，我选择了我的。</title>
		<link>http://www.zdave.net/archives/377?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=%25e4%25bd%25a0%25e9%2580%2589%25e6%258b%25a9%25e4%25ba%2586%25e4%25bd%25a0%25e7%259a%2584%25e8%25b7%25af%25ef%25bc%258c%25e6%2588%2591%25e9%2580%2589%25e6%258b%25a9%25e4%25ba%2586%25e6%2588%2591%25e7%259a%2584%25e3%2580%2582</link>
		<comments>http://www.zdave.net/archives/377#comments</comments>
		<pubDate>Thu, 11 Aug 2011 03:36:45 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[随笔日志]]></category>
		<category><![CDATA[Farewell]]></category>
		<category><![CDATA[斯内普]]></category>
		<category><![CDATA[莉莉]]></category>

		<guid isPermaLink="false">http://www.zdave.net/?p=377</guid>
		<description><![CDATA[一句“泥巴种”让他失去了莉莉的友谊，即使事后再如何地道歉也于事无补。 “你选择了你的路，我选择了我的。”莉莉的这句话让斯内普追悔一生。 就像当年那句“Farewell”。]]></description>
			<content:encoded><![CDATA[<p>一句“泥巴种”让他失去了莉莉的友谊，即使事后再如何地道歉也于事无补。</p>
<p>“你选择了你的路，我选择了我的。”莉莉的这句话让斯内普追悔一生。</p>
<p>就像当年那句“Farewell”。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/377/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP7 Isolated Storage详解系列导航</title>
		<link>http://www.zdave.net/archives/373?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wp7-isolated-storage%25e8%25af%25a6%25e8%25a7%25a3%25e7%25b3%25bb%25e5%2588%2597%25e5%25af%25bc%25e8%2588%25aa</link>
		<comments>http://www.zdave.net/archives/373#comments</comments>
		<pubDate>Fri, 10 Jun 2011 03:22:00 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Isolated Storage]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.zdave.net/archives/373</guid>
		<description><![CDATA[WP7 Isolated Storage详解(1)-Isolated Storage简介 WP7 Isolated Storage详解(2) &#8211; 文件与目录操作 WP7 Isolated Storage详解(3)-应用程序配置信息IsolatedStorageSettings WP7 Isolated Storage详解(4)-读写文本文件 WP7 Isolated Storage详解(5)-通过XmlSerializer读写XML文件 WP7 Isolated Storage详解(6)-通过XmlWriter读写XML文件 WP7 Isolated Storage详解(7)-读取、保存图片文件 WP7 Isolated Storage详解(8)-读取、保存二进制文件 本系列主要参考翻译自WindowsPhoneGeek的All about WP7 Isolated Storage。]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://www.zdave.net/archives/322" >WP7 Isolated Storage详解(1)-Isolated Storage简介</a></li>
<li><a href="http://www.zdave.net/archives/323" >WP7 Isolated Storage详解(2) &#8211; 文件与目录操作</a></li>
<li><a href="http://www.zdave.net/archives/328" >WP7 Isolated Storage详解(3)-应用程序配置信息IsolatedStorageSettings</a></li>
<li><a href="http://www.zdave.net/archives/332" >WP7 Isolated Storage详解(4)-读写文本文件</a></li>
<li><a href="http://www.zdave.net/archives/337" >WP7 Isolated Storage详解(5)-通过XmlSerializer读写XML文件</a></li>
<li><a href="http://www.zdave.net/archives/347" >WP7 Isolated Storage详解(6)-通过XmlWriter读写XML文件</a></li>
<li><a href="http://www.zdave.net/archives/369" >WP7 Isolated Storage详解(7)-读取、保存图片文件</a></li>
<li><a href="http://www.zdave.net/archives/371" >WP7 Isolated Storage详解(8)-读取、保存二进制文件</a></li>
</ul>
<p>本系列主要参考翻译自<a href="http://www.windowsphonegeek.com/" class="aga aga_2" target="_blank">WindowsPhoneGeek</a>的<a href="http://www.windowsphonegeek.com/tips/all-about-wp7-isolated-storage--intro-to-isolated-storage" class="aga aga_3" target="_blank">All about WP7 Isolated Storage</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/373/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP7 Isolated Storage详解(8)-读取、保存二进制文件</title>
		<link>http://www.zdave.net/archives/371?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wp7-isolated-storage%25e8%25af%25a6%25e8%25a7%25a38-%25e8%25af%25bb%25e5%258f%2596%25e3%2580%2581%25e4%25bf%259d%25e5%25ad%2598%25e4%25ba%258c%25e8%25bf%259b%25e5%2588%25b6%25e6%2596%2587%25e4%25bb%25b6</link>
		<comments>http://www.zdave.net/archives/371#comments</comments>
		<pubDate>Thu, 09 Jun 2011 05:56:00 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Isolated Storage]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.zdave.net/archives/371</guid>
		<description><![CDATA[二进制文件一般被认为是一组序列字节。一般来说一个二进制文件可能包含任何形式的二进制编码的数据类型。例如：.mp3文件，.jpg文件，.db文件都可以看做二进制文件。本篇内容将以MP3文件为例。 首先创建一个Windows Phone 7项目，在项目中添加一个MP3文件例如“Battery_Low.mp3”,然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间： using System.IO.IsolatedStorage; using System.IO; using System.Windows.Resources; 保存MP3文件到隔离存储空间 示例中首先检查文件是否已经存在，然后把“Battery_Low.mp3”文件保存到隔离存储空间。 我们首先创建一个文件流，然后使用BinaryWriter和BinaryReader在隔离层存储空间中创建一个新的MP3文件并且把“Battery_Low.mp3”的数据复制过去。 提示：分块读取文件有利于减少内存消耗和提高性能。 private const string FileName = &#34;Battery_Low.mp3&#34;; private void btnSave_Click(object sender, RoutedEventArgs e) { StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri(FileName, UriKind.Relative)); using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (myIsolatedStorage.FileExists(FileName)) { myIsolatedStorage.DeleteFile(FileName); } using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(FileName, FileMode.Create, myIsolatedStorage)) { using (BinaryWriter [...]]]></description>
			<content:encoded><![CDATA[<p>二进制文件一般被认为是一组序列字节。一般来说一个二进制文件可能包含任何形式的二进制编码的数据类型。例如：.mp3文件，.jpg文件，.db文件都可以看做二进制文件。本篇内容将以MP3文件为例。</p>
<p>首先创建一个Windows Phone 7项目，在项目中添加一个MP3文件例如“<em>Battery_Low.mp3</em>”,然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">using System.IO.IsolatedStorage;
using System.IO;
using System.Windows.Resources;</pre>
<h4><font style="font-weight: bold">保存MP3文件到隔离存储空间</font></h4>
<p>示例中首先检查文件是否已经存在，然后把“<em>Battery_Low.mp3</em>”文件保存到隔离存储空间。</p>
<p>我们首先创建一个文件流，然后使用BinaryWriter和BinaryReader在隔离层存储空间中创建一个新的MP3文件并且把“<em>Battery_Low.mp3</em>”的数据复制过去。</p>
<p>提示：分块读取文件有利于减少内存消耗和提高性能。</p>
<p><span id="more-371"></span></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">private const string FileName = &quot;Battery_Low.mp3&quot;;
private void btnSave_Click(object sender, RoutedEventArgs e)
{
    StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri(FileName, UriKind.Relative));

    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        if (myIsolatedStorage.FileExists(FileName))
        {
            myIsolatedStorage.DeleteFile(FileName);
        }

        using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(FileName, FileMode.Create, myIsolatedStorage))
        {
            using (BinaryWriter writer = new BinaryWriter(fileStream))
            {
                Stream resourceStream = streamResourceInfo.Stream;
                long length = resourceStream.Length;
                byte[] buffer = new byte[32];
                int readCount = 0;
                using (BinaryReader reader = new BinaryReader(streamResourceInfo.Stream))
                {
                    // read file in chunks in order to reduce memory consumption and increase performance
                    while (readCount &lt; length)
                    {
                        int actual = reader.Read(buffer, 0, buffer.Length);
                        readCount += actual;
                        writer.Write(buffer, 0, actual);
                    }
                }
            }
        }
    }
}</pre>
<h4><font style="font-weight: bold">从隔离存储空间中读取MP3文件</font></h4>
<p>示例中首先从隔离存储空间打开了一个名为<em>Battery_Low.mp3</em>的文件，并且把内容设置为一个媒体元素的数据源。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">private void btnRead_Click(object sender, RoutedEventArgs e)
{
    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(FileName, FileMode.Open, FileAccess.Read))
        {
            this.mediaElement.SetSource(fileStream);
        }
    }
}</pre>
<p>提示：&quot;mediaElement&quot;是一个在MainPage.xaml中的媒体元素：&lt;MediaElement x:Name=&quot;mediaElement&quot; AutoPlay=&quot;True&quot;/&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/371/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WP7 Isolated Storage详解(7)-读取、保存图片文件</title>
		<link>http://www.zdave.net/archives/369?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wp7-isolated-storage%25e8%25af%25a6%25e8%25a7%25a37-%25e8%25af%25bb%25e5%258f%2596%25e3%2580%2581%25e4%25bf%259d%25e5%25ad%2598%25e5%259b%25be%25e7%2589%2587%25e6%2596%2587%25e4%25bb%25b6</link>
		<comments>http://www.zdave.net/archives/369#comments</comments>
		<pubDate>Wed, 01 Jun 2011 10:17:00 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Isolated Storage]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.zdave.net/archives/369</guid>
		<description><![CDATA[首先创建一个Windows Phone 7项目，在项目中添加一个图片例如“logo.jpg”,然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间： using System.IO.IsolatedStorage; using System.Windows.Media.Imaging; using System.IO; using System.Windows.Resources; using Microsoft.Xna.Framework.Media; using Microsoft.Phone.Tasks; 提示：Microsoft.Xna.Framework.Media;仅当你要把图片保存到媒体库的时候才需要添加引用。 对于很多应用，向隔离存储空间读取、保存图片文件是很常见的任务。在WP7中，你还可以保存、读取媒体库中的图片。 一般情况下我们使用类IsolatedStorageFileStream进行读、写、创建文件等操作。对于图片，最大的不同就是使用类BitmapImage和类WriteableBitmap. 保存图片到隔离存储空间 示例中首先检查文件是否已经存在，然后把图片保存到隔离存储空间（转换WriteableBitmap对象到JPEG stream）。 String tempJPEG = &#34;logo.jpg&#34;; using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (myIsolatedStorage.FileExists(tempJPEG)) { myIsolatedStorage.DeleteFile(tempJPEG); } IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG); StreamResourceInfo sri = null; Uri uri = new Uri(tempJPEG, UriKind.Relative); sri = Application.GetResourceStream(uri); BitmapImage bitmap [...]]]></description>
			<content:encoded><![CDATA[<p>首先创建一个Windows Phone 7项目，在项目中添加一个图片例如“logo.jpg”,然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows.Resources;
using Microsoft.Xna.Framework.Media;
using Microsoft.Phone.Tasks;</pre>
<p>提示：<em>Microsoft.Xna.Framework.Media;</em>仅当你要把图片保存到媒体库的时候才需要添加引用。</p>
<p>对于很多应用，向隔离存储空间读取、保存图片文件是很常见的任务。在WP7中，你还可以保存、读取媒体库中的图片。</p>
<p><span id="more-369"></span></p>
<p>一般情况下我们使用类<a href="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefilestream%28v=VS.90%29.aspx" class="aga aga_5">IsolatedStorageFileStream</a>进行读、写、创建文件等操作。对于图片，最大的不同就是使用类BitmapImage和类WriteableBitmap.</p>
<h4><font style="font-weight: bold">保存图片到隔离存储空间</font></h4>
<p>示例中首先检查文件是否已经存在，然后把图片保存到隔离存储空间（转换WriteableBitmap对象到JPEG stream）。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">            String tempJPEG = &quot;logo.jpg&quot;;

            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists(tempJPEG))
                {
                    myIsolatedStorage.DeleteFile(tempJPEG);
                }

                IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);

                StreamResourceInfo sri = null;
                Uri uri = new Uri(tempJPEG, UriKind.Relative);
                sri = Application.GetResourceStream(uri);

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(sri.Stream);
                WriteableBitmap wb = new WriteableBitmap(bitmap);

                // Encode WriteableBitmap object to a JPEG stream.
                Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);

                fileStream.Close();
            }</pre>
<p>提示：你也可以使用WriteableBitmap来保存图片：wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);</p>
<h4><font style="font-weight: bold">从隔离存储空间读取图片</font></h4>
<p>示例中首先从隔离存储空间打开了一个名为logo.jpg的图片，并在一个Image控件中呈现出来。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">BitmapImage bi = new BitmapImage();

            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(&quot;logo.jpg&quot;, FileMode.Open, FileAccess.Read))
                {
                    bi.SetSource(fileStream);
                    this.img.Height = bi.PixelHeight;
                    this.img.Width = bi.PixelWidth;
                }
            }
            this.img.Source = bi;</pre>
<p>提示：“img”是一个在MainPage.xaml中的图片控件：&lt;Image x:Name=&quot;img&quot;/&gt;</p>
<h4><font style="font-weight: bold">保存图片到手机媒体库</font></h4>
<p>访问MediaLibrary需要在项目中添加引用：Microsoft.XNA.Framework。</p>
<p>示例中从隔离存储空间中读取一个图片，然后保存到手机的媒体库中。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(&quot;logo.jpg&quot;, FileMode.Open, FileAccess.Read))
                {
                    MediaLibrary mediaLibrary = new MediaLibrary();
                    Picture pic = mediaLibrary.SavePicture(&quot;SavedLogo.jpg&quot;, fileStream);
                    fileStream.Close();
                }
            }

            PhotoChooserTask photoChooserTask = new PhotoChooserTask();
            photoChooserTask.Show();</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/369/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Dev Day &#8211; WP7优秀应用经验分享日总结</title>
		<link>http://www.zdave.net/archives/367?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mobile-dev-day-wp7%25e4%25bc%2598%25e7%25a7%2580%25e5%25ba%2594%25e7%2594%25a8%25e7%25bb%258f%25e9%25aa%258c%25e5%2588%2586%25e4%25ba%25ab%25e6%2597%25a5%25e6%2580%25bb%25e7%25bb%2593</link>
		<comments>http://www.zdave.net/archives/367#comments</comments>
		<pubDate>Sat, 28 May 2011 14:18:00 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Mobile Dev Day]]></category>
		<category><![CDATA[OpenXLive]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[新浪微博.Viva]]></category>

		<guid isPermaLink="false">http://www.zdave.net/archives/367</guid>
		<description><![CDATA[今天下午有幸参加了Mobile Dev Day移动技术研讨沙龙活动，主题是“WP7优秀应用经验分享日”。活动中来自新浪微博、Viva电子杂志以及OpenXLive团队的朋友分享了一些他们在WP7平台上的产品的一些心得体会。 新浪微博 新浪微博主要是由汪佐怀进行讲解。对于WP7的主要有以下几点： 整体架构采用MVVM模式。 MVVM在WPF/Silverlight/WP7中算是很常用的一种模式，相信大家都不陌生。同时也提到了WP7下MVVM模式的Command支持的不够好。 新浪微博的演讲结束后，去请教他们的主要开发者，了解到他们目前对MVVM模式的Command实现也是基于MVVMLight的扩展。 主界面微博列表的显示 新浪微博的列表显示采用了LazyListBox控件。LazyListBox控件主要用于比较长的items显示，例如文本+图片。它可以使你在滑动的时候可以使用不同模板,例如滑动时只加载文本，滑动停止时加载文本+图片。 汪老师同时提出为了保证滑动时候的流畅，建议在滑动的时候停止一切网络请求。在提问环节中，有人问到为何不单独开启线程请求数据。汪老师解释单独开启进程同样会使用系统资源，使滑动不够流畅。个人觉得应该没有人会在UI线程进行数据请求吧。 图片的显示 由于WP7中没有原生支持GIF图片的显示，所以新浪微博采用了imagetool来实现。 缓存的处理 在开发过程中对隔离存储空间的监控通过Isolated Storage Explorer，这个大家想必都了解。据说在Mango中就可以直接查看了。 根据现场观众提问的回答，新浪微博目前在隔离存储空间缓存200条最新微博（不确定，汪老师说的是大概）。 微博程序的换肤 新浪微博目前提供了三种皮肤选择，两种白天一种夜间模式。切换皮肤后必须重启才能生效。 之前也给WP7的应用做过皮肤，其中的类似皮肤资源文件一旦加载的确是无法修改的，只能通过重启生效。 其他 汪老师同时也讲了许多其他的内容，包括以前Windows Mobile平台上的一些开发经验。 Pivot控件的一个问题，例如跳转到的目标页是一个Pivot页面，跳转后想显示的PivotItem的Index不是第一个（还有第二个、倒数第一个），那么只能在页面的Loaded里让他的SelectedIndex改变为预期值。这时候的页面会有一个滑动翻转效果。之前尝试过在Pivot页面的构造函数或者重写页面的OnNavigateTo或者XAML中SelectedIndex绑定ViewModel，在点击非第一个、第二个或者倒数第一个PivotItem均报异常，所以猜测Pivot控件只会预加载这三个PivotItem。新浪微博的开发者们目前也遇到了这个问题。 Viva电子杂志 Viva电子杂志主要是由陈禹辰进行讲解，并现场制作了一本示例电子杂志。内容要点如下： Viva电子杂志App的分类 Viva电子杂志在WP7平台上的杂志应用主要分为两种，通用的客户端和单行本的客户端。通用客户端的数据是通过网络请求，单行本的数据则是打包到xap文件中去。目前通用版本免费，单行本版本收费。 杂志的缓存处理 通用版本缓存保存前一天所浏览过的杂志内容，单行本版本内容打包到xap中，无需缓存。 制作一本单行本电子杂志 讲解了如何利用Pivot控件结合WP7的数据绑定特性以及通过模板制作一本电子杂志。 实现自动化打包电子杂志 通过修改项目文件（*.csproj）与WMAppManifest.xml文件内容，规范的杂志内容图片命名，配合命令行实现自动化打包。 TextBlock控件内容过长的问题 目前WP7上TextBlock空间的宽和高上限为2048px，超过这个数值的内容将被截断。由于高宽有上限，所以TextBlock显示的字符长度还与字体大小有关。Viva电子杂志的做法是不开放用户自定义字体大小，然后对每一页杂志内容的文本长度进行判断，寻找每500个字符前面最近的一个回车进行分割，然后显示在一个或多个TextBlock上。 Pivot控件内存问题 目前256M内存WP7上应用最多使用90M内存，512M为290M。在WP7的Pivot控件中，滑动过的页面的内存没有及时自动释放。 Viva电子杂志演示了一个40页左右的杂志，当滑动到最后几页时，内存使用超过了290M，然后应用出现显示空白等异常。 Viva电子杂志目前的解决方案是自己写了一个页面用来显示具体页得杂志内容，自己实现杂志的滑动效果，内存监视显示大约30-40M，是一种比较理想的结果。 OpenXLive OpenXLive主要是由黄炜元进行演讲，主要讲解WP7的开发者如何使用OpenXLive的服务开发出更理想的游戏产品。 OpenXLive是Windows Phone 7上的游戏社交平台，为个人开发者免费提供游戏在线服务。他们目前提供在线积分榜、游戏成就、社交网络等功能。 在演示中，大约只添加了10行左右的代码，就能使用到OpenXLive的各种功能，实为WP7上开发游戏的得力助手。 除了丰富的演讲与技术交流之外，在场的观众都收到了WP7主题笔记本、贴纸、光盘、U盘。新浪微博、Viva电子杂志、OpenXLive还送出了抱枕、音箱、T恤等礼品。]]></description>
			<content:encoded><![CDATA[<p>今天下午有幸参加了Mobile Dev Day移动技术研讨沙龙活动，主题是“WP7优秀应用经验分享日”。活动中来自新浪微博、Viva电子杂志以及OpenXLive团队的朋友分享了一些他们在WP7平台上的产品的一些心得体会。</p>
<h4><strong>新浪微博</strong></h4>
<p>新浪微博主要是由<strong>汪佐怀</strong>进行讲解。对于WP7的主要有以下几点：</p>
<ol>
<li><strong>整体架构采用MVVM模式。</strong>
<p>MVVM在WPF/Silverlight/WP7中算是很常用的一种模式，相信大家都不陌生。同时也提到了WP7下MVVM模式的Command支持的不够好。</p>
<p>新浪微博的演讲结束后，去请教他们的主要开发者，了解到他们目前对MVVM模式的Command实现也是基于MVVMLight的扩展。</p>
</li>
<li><strong>主界面微博列表的显示</strong>
<p>新浪微博的列表显示采用了LazyListBox控件。LazyListBox控件主要用于比较长的items显示，例如文本+图片。它可以使你在滑动的时候可以使用不同模板,例如滑动时只加载文本，滑动停止时加载文本+图片。</p>
<p><strong>汪老师</strong>同时提出为了保证滑动时候的流畅，建议在滑动的时候停止一切网络请求。在提问环节中，有人问到为何不单独开启线程请求数据。汪老师解释单独开启进程同样会使用系统资源，使滑动不够流畅。个人觉得应该没有人会在UI线程进行数据请求吧。</p>
</li>
<li><strong>图片的显示</strong>
<p>由于WP7中没有原生支持GIF图片的显示，所以新浪微博采用了imagetool来实现。</p>
</li>
<li><strong>缓存的处理</strong>
<p>在开发过程中对隔离存储空间的监控通过Isolated Storage Explorer，这个大家想必都了解。据说在Mango中就可以直接查看了。</p>
<p>根据现场观众提问的回答，新浪微博目前在隔离存储空间缓存200条最新微博（不确定，汪老师说的是大概）。</p>
</li>
<li><strong>微博程序的换肤</strong>
<p>新浪微博目前提供了三种皮肤选择，两种白天一种夜间模式。切换皮肤后必须重启才能生效。</p>
<p>之前也给WP7的应用做过皮肤，其中的类似皮肤资源文件一旦加载的确是无法修改的，只能通过重启生效。</p>
</li>
<li><strong>其他</strong>
<p>汪老师同时也讲了许多其他的内容，包括以前Windows Mobile平台上的一些开发经验。</p>
<p>Pivot控件的一个问题，例如跳转到的目标页是一个Pivot页面，跳转后想显示的PivotItem的Index不是第一个（还有第二个、倒数第一个），那么只能在页面的Loaded里让他的SelectedIndex改变为预期值。这时候的页面会有一个滑动翻转效果。之前尝试过在Pivot页面的构造函数或者重写页面的OnNavigateTo或者XAML中SelectedIndex绑定ViewModel，在点击非第一个、第二个或者倒数第一个PivotItem均报异常，所以猜测Pivot控件只会预加载这三个PivotItem。新浪微博的开发者们目前也遇到了这个问题。</p>
</li>
</ol>
<p><span id="more-367"></span><br />
<h4><strong>Viva电子杂志</strong></h4>
<p>Viva电子杂志主要是由<strong>陈禹辰</strong>进行讲解，并现场制作了一本示例电子杂志。内容要点如下：</p>
<ol>
<li><strong>Viva电子杂志App的分类</strong>
<p>Viva电子杂志在WP7平台上的杂志应用主要分为两种，通用的客户端和单行本的客户端。通用客户端的数据是通过网络请求，单行本的数据则是打包到xap文件中去。目前通用版本免费，单行本版本收费。</p>
</li>
<li><strong>杂志的缓存处理</strong>
<p>通用版本缓存保存前一天所浏览过的杂志内容，单行本版本内容打包到xap中，无需缓存。</p>
</li>
<li><strong>制作一本单行本电子杂志</strong>
<p>讲解了如何利用Pivot控件结合WP7的数据绑定特性以及通过模板制作一本电子杂志。</p>
</li>
<li><strong>实现自动化打包电子杂志</strong>
<p>通过修改项目文件（*.csproj）与WMAppManifest.xml文件内容，规范的杂志内容图片命名，配合命令行实现自动化打包。</p>
</li>
<li><strong>TextBlock控件内容过长的问题</strong>
<p>目前WP7上TextBlock空间的宽和高上限为2048px，超过这个数值的内容将被截断。由于高宽有上限，所以TextBlock显示的字符长度还与字体大小有关。Viva电子杂志的做法是不开放用户自定义字体大小，然后对每一页杂志内容的文本长度进行判断，寻找每500个字符前面最近的一个回车进行分割，然后显示在一个或多个TextBlock上。</p>
</li>
<li><strong>Pivot控件内存问题</strong>
<p>目前256M内存WP7上应用最多使用90M内存，512M为290M。在WP7的Pivot控件中，滑动过的页面的内存没有及时自动释放。</p>
<p>Viva电子杂志演示了一个40页左右的杂志，当滑动到最后几页时，内存使用超过了290M，然后应用出现显示空白等异常。</p>
<p>Viva电子杂志目前的解决方案是自己写了一个页面用来显示具体页得杂志内容，自己实现杂志的滑动效果，内存监视显示大约30-40M，是一种比较理想的结果。</p>
</li>
</ol>
<p><strong>OpenXLive</strong></p>
<p>OpenXLive主要是由<strong>黄炜元</strong>进行演讲，主要讲解WP7的开发者如何使用OpenXLive的服务开发出更理想的游戏产品。</p>
<blockquote><p>OpenXLive是Windows Phone 7上的游戏社交平台，为个人开发者免费提供游戏在线服务。他们目前提供在线积分榜、游戏成就、社交网络等功能。</p>
<p>在演示中，大约只添加了10行左右的代码，就能使用到OpenXLive的各种功能，实为WP7上开发游戏的得力助手。</p>
</blockquote>
<p>除了丰富的演讲与技术交流之外，在场的观众都收到了WP7主题笔记本、贴纸、光盘、U盘。新浪微博、Viva电子杂志、OpenXLive还送出了抱枕、音箱、T恤等礼品。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/367/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>腾讯QQ-WP7版发布</title>
		<link>http://www.zdave.net/archives/365?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=%25e8%2585%25be%25e8%25ae%25afqq-wp7%25e7%2589%2588%25e5%258f%2591%25e5%25b8%2583</link>
		<comments>http://www.zdave.net/archives/365#comments</comments>
		<pubDate>Sat, 28 May 2011 03:30:00 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[QQ]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.zdave.net/archives/365</guid>
		<description><![CDATA[手机QQ for Windows Phone 7终于发布了，自带中文输入法，支持push，支持与PC同时在线。UI交互上做的挺好。 PS：刚试用就发现一个bug，可能是没做墓碑化处理吧，最小化回来再次激活的时候，联系人里面一片空白。 相关信息： 【版本特性】 1.支持C2C/群聊天 2.支持自定义头像的显示 3.支持修改个性签名 4.支持添加好友和本地搜索 5..可发送QQ表情 6.丰富的应用列表 7.自带中文输入法，聊天无障碍 8.在个人中心对消息进行集中管理，方便更贴心 9.颠覆传统长连接方式，收发消息及时且省电省流量 10.支持对离线消息的push 11.支持与PC同时在线，同一个QQ帐号在电脑和手机端均可收发消息 12.贴合系统的UI交互，视觉清新，操作便捷 【官方论坛】[Official forum] http://lt.3g.qq.com/g/topic_list.jsp?forumId=1983 【反馈建议】[feedback] http://wap.3g.qq.com/g/s?aid=wapsupport&#38;fid=625 【官方微博】[Official Tencent Weibo] http://t.qq.com/MobileQQ &#160; &#160;]]></description>
			<content:encoded><![CDATA[<p>手机QQ for Windows Phone 7终于发布了，自带中文输入法，支持push，支持与PC同时在线。UI交互上做的挺好。</p>
<p>PS：刚试用就发现一个bug，可能是没做墓碑化处理吧，最小化回来再次激活的时候，联系人里面一片空白。</p>
<p>相关信息：</p>
<p>【版本特性】</p>
<p>1.支持C2C/群聊天    <br />2.支持自定义头像的显示     <br />3.支持修改个性签名     <br />4.支持添加好友和本地搜索     <br />5..可发送QQ表情     <br />6.丰富的应用列表     <br />7.自带中文输入法，聊天无障碍     <br />8.在个人中心对消息进行集中管理，方便更贴心     <br />9.颠覆传统长连接方式，收发消息及时且省电省流量     <br />10.支持对离线消息的push     <br />11.支持与PC同时在线，同一个QQ帐号在电脑和手机端均可收发消息     <br />12.贴合系统的UI交互，视觉清新，操作便捷     <span id="more-365"></span><br />【官方论坛】[Official forum]     <br /><a href="http://lt.3g.qq.com/g/topic_list.jsp?forumId=1983" class="aga aga_9">http://lt.3g.qq.com/g/topic_list.jsp?forumId=1983</a>     <br />【反馈建议】[feedback]     <br /><a href="http://wap.3g.qq.com/g/s?aid=wapsupport&amp;fid=625" class="aga aga_10">http://wap.3g.qq.com/g/s?aid=wapsupport&amp;fid=625</a>     <br />【官方微博】[Official Tencent Weibo]     <br /><a href="http://t.qq.com/MobileQQ " class="aga aga_11">http://t.qq.com/MobileQQ </a></p>
<p>&#160;</p>
<p><a href="http://www.zdave.net/wp-content/uploads/2011/05/1.png" ><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="1" border="0" alt="1" src="http://www.zdave.net/wp-content/uploads/2011/05/1_thumb.png" width="484" height="804" /></a></p>
<p>&#160;</p>
<p><a href="http://www.zdave.net/wp-content/uploads/2011/05/2.png" ><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="2" border="0" alt="2" src="http://www.zdave.net/wp-content/uploads/2011/05/2_thumb.png" width="484" height="804" /></a></p>
<p><a href="http://www.zdave.net/wp-content/uploads/2011/05/3.png" ><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="3" border="0" alt="3" src="http://www.zdave.net/wp-content/uploads/2011/05/3_thumb.png" width="484" height="804" /></a></p>
<p><a href="http://www.zdave.net/wp-content/uploads/2011/05/4.png" ><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="4" border="0" alt="4" src="http://www.zdave.net/wp-content/uploads/2011/05/4_thumb.png" width="484" height="804" /></a></p>
<p><a href="http://www.zdave.net/wp-content/uploads/2011/05/5.png" ><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="5" border="0" alt="5" src="http://www.zdave.net/wp-content/uploads/2011/05/5_thumb.png" width="484" height="804" /></a></p>
<p><a href="http://www.zdave.net/wp-content/uploads/2011/05/6.png" ><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="6" border="0" alt="6" src="http://www.zdave.net/wp-content/uploads/2011/05/6_thumb.png" width="484" height="804" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/365/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP7 Isolated Storage详解(6)-通过XmlWriter读写XML文件</title>
		<link>http://www.zdave.net/archives/347?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wp7-isolated-storage%25e8%25af%25a6%25e8%25a7%25a36-%25e9%2580%259a%25e8%25bf%2587xmlwriter%25e8%25af%25bb%25e5%2586%2599xml%25e6%2596%2587%25e4%25bb%25b6</link>
		<comments>http://www.zdave.net/archives/347#comments</comments>
		<pubDate>Thu, 26 May 2011 10:07:00 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Isolated Storage]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.zdave.net/archives/347</guid>
		<description><![CDATA[首先创建一个Windows Phone 7项目，然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间： using System.Xml; using System.IO.IsolatedStorage; using System.IO; 使用XmlWriter保存XML文件到隔离存储空间 示例中创建了一个名为People2.xml的XML文件并写入数据。 using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("People2.xml", FileMode.Create, myIsolatedStorage)) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create(isoStream, settings)) { writer.WriteStartElement("p", "person", "urn:person"); writer.WriteStartElement("FirstName", ""); writer.WriteString("Kate"); writer.WriteEndElement(); writer.WriteStartElement("LastName", ""); writer.WriteString("Brown"); writer.WriteEndElement(); writer.WriteStartElement("Age", ""); writer.WriteString("25"); [...]]]></description>
			<content:encoded><![CDATA[<p>首先创建一个Windows Phone 7项目，然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">using System.Xml;
using System.IO.IsolatedStorage;
using System.IO;</pre>
<p><strong> </strong></p>
<p><strong></p>
<h4><strong>使用XmlWriter保存XML文件到隔离存储空间</strong></h4>
<p></strong></p>
<p><strong> </strong></p>
<p>示例中创建了一个名为<em>People2.xml</em>的XML文件并写入数据。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("People2.xml", FileMode.Create, myIsolatedStorage))
    {
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        using (XmlWriter writer = XmlWriter.Create(isoStream, settings))
        {

            writer.WriteStartElement("p", "person", "urn:person");
            writer.WriteStartElement("FirstName", "");
            writer.WriteString("Kate");
            writer.WriteEndElement();
            writer.WriteStartElement("LastName", "");
            writer.WriteString("Brown");
            writer.WriteEndElement();
            writer.WriteStartElement("Age", "");
            writer.WriteString("25");
            writer.WriteEndElement();
            // Ends the document
            writer.WriteEndDocument();
            // Write the XML to the file.
            writer.Flush();
        }
    }
}</pre>
<p><span id="more-347"></span></p>
<h4><span style="font-weight: bold;">使用<strong><strong>StreamReader</strong></strong>从隔离存储空间中读取XML文件</span></h4>
<p>示例中打开了一个已存在的文件<em>People2.xml</em>并读取它的内容。然后把数据显示在一个TextBlock 上。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">try
{
    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        IsolatedStorageFileStream isoFileStream = myIsolatedStorage.OpenFile("People2.xml", FileMode.Open);
        using (StreamReader reader = new StreamReader(isoFileStream))
        {
            this.tbx.Text = reader.ReadToEnd();
        }
    }
}
catch
{ }</pre>
<p>提示：当进行文件操作的时候始终使用<strong>using</strong>关键字，<strong>using</strong>结束后会隐式调用Disposable方法，清理非托管资源。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/347/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WP7 Isolated Storage详解(5)-通过XmlSerializer读写XML文件</title>
		<link>http://www.zdave.net/archives/337?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wp7-isolated-storage%25e8%25af%25a6%25e8%25a7%25a35-%25e9%2580%259a%25e8%25bf%2587xmlserializer%25e8%25af%25bb%25e5%2586%2599xml%25e6%2596%2587%25e4%25bb%25b6</link>
		<comments>http://www.zdave.net/archives/337#comments</comments>
		<pubDate>Mon, 23 May 2011 07:09:00 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Isolated Storage]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.zdave.net/archives/337</guid>
		<description><![CDATA[首先创建一个Windows Phone 7项目，然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间： using System.Xml; using System.Xml.Serialization; using System.IO.IsolatedStorage; using System.IO; 提示：你需要在项目中添加System.Xml.Serialization引用。 对于很多应用，向隔离存储空间读写XML文件是很常见的任务。 一般情况下我们使用类IsolatedStorageFileStream进行读、写、创建文件等操作。与使用XmlWriter不同的是，XmlSerializer使我们更方便的在Object和XML文档之间进行序列化与反序列化转换。 本篇中我们将使用如下的Person类来生成XML文件结构： public class Person { string firstname; string lastname; int age; public string FirstName { get { return firstname; } set { firstname = value; } } public string LastName { get { return lastname; } set { lastname = value; [...]]]></description>
			<content:encoded><![CDATA[<p>首先创建一个Windows Phone 7项目，然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">using System.Xml;
using System.Xml.Serialization;
using System.IO.IsolatedStorage;
using System.IO;</pre>
<p>提示：你需要在项目中添加<em>System.Xml.Serialization</em>引用。</p>
<p>对于很多应用，向隔离存储空间读写XML文件是很常见的任务。</p>
<p>一般情况下我们使用类<a href="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefilestream%28v=VS.90%29.aspx" class="aga aga_13">IsolatedStorageFileStream</a>进行读、写、创建文件等操作。与使用XmlWriter不同的是，XmlSerializer使我们更方便的在Object和XML文档之间进行序列化与反序列化转换。</p>
<p><span id="more-337"></span></p>
<p>本篇中我们将使用如下的Person类来生成XML文件结构：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">public class Person
{
    string firstname;
    string lastname;
    int age;

    public string FirstName
    {
        get { return firstname; }
        set { firstname = value; }
    }

    public string LastName
    {
        get { return lastname; }
        set { lastname = value; }
    }

    public int Age
    {
        get { return age; }
        set { age = value; }
    }
}</pre>
<p>将要被序列化的数据对象：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">private List&lt;Person&gt; GeneratePersonData()
{
    List&lt;Person&gt; data = new List&lt;Person&gt;();
    data.Add(new Person() { FirstName = &quot;Kate&quot;, LastName = &quot;Brown&quot;, Age = 25 });
    data.Add(new Person() { FirstName = &quot;Tom&quot;, LastName = &quot;Stone&quot;, Age = 63 });
    data.Add(new Person() { FirstName = &quot;Michael&quot;, LastName = &quot;Liberty&quot;, Age = 37 });
    return data;
}</pre>
<h4></h4>
<h4><font style="font-weight: bold">使用XmlSerializer 保存XML文件到隔离存储空间</font></h4>
<p>示例中创建了一个名为<em>People.xml</em>的XML文件并写入数据。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">// Write to the Isolated Storage
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;

using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile(&quot;People.xml&quot;, FileMode.Create))
    {
        XmlSerializer serializer = new XmlSerializer(typeof(List&lt;Person&gt;));
        using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
        {
            serializer.Serialize(xmlWriter, GeneratePersonData());
        }
    }
}</pre>
<p>提示：创建文件使用<em>FileMode.Create，</em>写入内容使用<em>FileAccess.Write</em>。<em>FileAccess</em>的成员共有Read、Write、ReadWrite三种。</p>
<h4><font style="font-weight: bold">使用XmlSerializer从隔离存储空间中读取XML文件</font></h4>
<p>示例中打开了一个已存在的文件<em>People.xml</em>并读取它的内容。然后把数据显示在一个ListBox上。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">try
{
    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using(IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile(&quot;People.xml&quot;, FileMode.Open))
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List&lt;Person&gt;));
            List&lt;Person&gt; data = (List&lt;Person&gt;)serializer.Deserialize(stream);
            this.listBox.ItemsSource = data;
        }
    }
}
catch
{
    //add some code here
}</pre>
<p>提示：打开已存在文件使用<em>FileMode.Open</em>,读取内容使用FileAccess.Read。</p>
<pre class="brush: html; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">&lt;ListBox x:Name=&quot;listBox&quot;&gt;
    &lt;ListBox.ItemTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;StackPanel Margin=&quot;10&quot; &gt;
                &lt;TextBlock Text=&quot;{Binding FirstName}&quot;/&gt;
                &lt;TextBlock Text=&quot;{Binding LastName}&quot;/&gt;
                &lt;TextBlock Text=&quot;{Binding Age}&quot;/&gt;
            &lt;/StackPanel&gt;
        &lt;/DataTemplate&gt;
    &lt;/ListBox.ItemTemplate&gt;
&lt;/ListBox&gt;</pre>
<p>提示：当进行文件操作的时候始终使用<strong>using</strong>关键字，<strong>using</strong>结束后会隐式调用Disposable方法，清理非托管资源。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/337/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP7 Isolated Storage详解(4)-读写文本文件</title>
		<link>http://www.zdave.net/archives/332?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wp7-isolated-storage%25e8%25af%25a6%25e8%25a7%25a34-%25e8%25af%25bb%25e5%2586%2599%25e6%2596%2587%25e6%259c%25ac%25e6%2596%2587%25e4%25bb%25b6</link>
		<comments>http://www.zdave.net/archives/332#comments</comments>
		<pubDate>Tue, 10 May 2011 05:09:00 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Isolated Storage]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.zdave.net/archives/332</guid>
		<description><![CDATA[首先创建一个Windows Phone 7项目，然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间： using System.IO; using System.IO.IsolatedStorage; 我们使用类IsolatedStorageFileStream在隔离存储空间中进行读、写、创建文件的操作。这个类继承自FileStream，所以在通常使用FileStream的地方都可以使用IsolatedStorageFileStream，例如StreamReader 和 StreamWriter。 创建文本文件 示例中我们创建了一个名称为myFile.txt的文本文件，并写入了一些内容。 IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); //create new file using (StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream(&#34;myFile.txt&#34;, FileMode.Create, FileAccess.Write, myIsolatedStorage))) { string someTextData = &#34;This is some text data to be saved in a new text file in the IsolatedStorage!&#34;; writeFile.WriteLine(someTextData); writeFile.Close(); } 提示：创建文件使用FileMode.Create，写入内容使用FileAccess.Write。FileAccess的成员共有Read、Write、ReadWrite三种。 向已存在文件写入 示例中打开了一个已存在的名称为myFile.txt的文本文件，并追加了一些内容。 [...]]]></description>
			<content:encoded><![CDATA[<p>首先创建一个Windows Phone 7项目，然后在MainPage.xaml.cs（或其他页面文件）中引入命名空间：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">using System.IO;
using System.IO.IsolatedStorage;</pre>
<p>我们使用类<a href="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefilestream%28v=VS.90%29.aspx" class="aga aga_19">IsolatedStorageFileStream</a>在隔离存储空间中进行读、写、创建文件的操作。这个类继承自<a href="http://msdn.microsoft.com/en-us/library/system.io.filestream%28v=VS.90%29.aspx" class="aga aga_20">FileStream</a>，所以在通常使用<a href="http://msdn.microsoft.com/en-us/library/system.io.filestream%28v=VS.90%29.aspx" class="aga aga_21">FileStream</a>的地方都可以使用IsolatedStorageFileStream，例如<a href="http://msdn.microsoft.com/en-us/library/system.io.streamreader%28v=VS.90%29.aspx" class="aga aga_22">StreamReader</a> 和 <a href="http://msdn.microsoft.com/en-us/library/system.io.streamwriter%28v=VS.90%29.aspx" class="aga aga_23">StreamWriter</a>。</p>
<h4><font style="font-weight: bold">创建文本文件</font></h4>
<p>示例中我们创建了一个名称为<em>myFile.txt</em>的文本文件，并写入了一些内容。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

//create new file
using (StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream(&quot;myFile.txt&quot;, FileMode.Create, FileAccess.Write, myIsolatedStorage)))
{
    string someTextData = &quot;This is some text data to be saved in a new text file in the IsolatedStorage!&quot;;
    writeFile.WriteLine(someTextData);
    writeFile.Close();
}</pre>
<p>提示：创建文件使用<em>FileMode.Create，</em>写入内容使用<em>FileAccess.Write</em>。<em>FileAccess</em>的成员共有Read、Write、ReadWrite三种。</p>
<p><span id="more-332"></span></p>
<h4><font style="font-weight: bold">向已存在文件写入</font></h4>
<p>示例中打开了一个已存在的名称为<em>myFile.txt</em>的文本文件，并追加了一些内容。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

//Open existing file
IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(&quot;myFile.txt&quot;, FileMode.Open, FileAccess.Write);
using (StreamWriter writer = new StreamWriter(fileStream))
{
    string someTextData = &quot;Some More TEXT Added:  !&quot;;
    writer.Write(someTextData);
    writer.Close();
}</pre>
<p>提示：打开已存在文件使用<em>FileMode.Open</em>,读取内容使用FileAccess.Read。</p>
<h4><font style="font-weight: bold">在目录中进行读写操作</font></h4>
<ul>
<li>写入 </li>
</ul>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">//Obtain the virtual store for application
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

//Create a new folder and call it &quot;ImageFolder&quot;
myIsolatedStorage.CreateDirectory(&quot;TextFilesFolder&quot;);

//Create a new file and assign a StreamWriter to the store and this new file (myFile.txt)
//Also take the text contents from the txtWrite control and write it to myFile.txt
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream(&quot;TextFilesFolder\\myNewFile.txt&quot;, FileMode.OpenOrCreate, myIsolatedStorage));
string someTextData = &quot;This is some text data to be saved in a new text file in the IsolatedStorage!&quot;;
writeFile.WriteLine(someTextData);
writeFile.Close();</pre>
<ul>
<li>读取 </li>
</ul>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(&quot;TextFilesFolder\\myNewFile.txt&quot;, FileMode.Open, FileAccess.Read);
using (StreamReader reader = new StreamReader(fileStream))
{
    this.text1.Text = reader.ReadLine();
}</pre>
<h4><font style="font-weight: bold">最佳方式</font></h4>
<p>1）当进行文件操作的时候始终使用<font color="#4f81bd"><strong>Using</strong></font>关键字，<font color="#4f81bd"><strong>Using</strong></font><font color="#000000">结束后会隐式调用Disposable方法，清理非托管资源。</font></p>
<p>2）检查将要进行读写操作的文件所在目录是否存在。</p>
<p>3）读取前判断文件是否存在。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/332/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dictionary&lt;TKey,TValue&gt; 中的查询-ContainsKey与TryGetValue</title>
		<link>http://www.zdave.net/archives/330?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dictionarytkeytvalue-%25e4%25b8%25ad%25e7%259a%2584%25e6%259f%25a5%25e8%25af%25a2-containskey%25e4%25b8%258etrygetvalue</link>
		<comments>http://www.zdave.net/archives/330#comments</comments>
		<pubDate>Mon, 09 May 2011 06:54:00 +0000</pubDate>
		<dc:creator>Zdave</dc:creator>
				<category><![CDATA[DotNet]]></category>
		<category><![CDATA[Dictionary，ContainsKey，TryGetValue]]></category>

		<guid isPermaLink="false">http://www.zdave.net/archives/330</guid>
		<description><![CDATA[在之前一篇关于WP7 IsolatedStorageSettings的文章结尾，给出了一个“最佳方式”： -在尝试读取一个对象之前检查目标是否存在。 if(settings.Contains(&#34;myemail&#34;)) { ... } 博客园的博友aGan@net提出“最佳方式应该是TryGetValue，而不是检测Contains，前者性能更高”。 于是用Reflector看了一下微软的实现。 IsolatedStorageSettings.ApplicationSettings的Contains实际调用Dictionary&#60;TKey,TValue&#62;的ContainsKey方法： public bool ContainsKey(TKey key) { return this.FindEntry(key) &#62;= 0; } TryGetValue方法： public bool TryGetValue(TKey key, out TValue value) { int index = this.FindEntry(key); if (index &#62;= 0) { value = this.entries[index].value; return true; } value = default(TValue); return false; } TValue： public TValue this[TKey key] [...]]]></description>
			<content:encoded><![CDATA[<p>在之前一篇关于WP7 IsolatedStorageSettings的文章结尾，给出了一个“最佳方式”：</p>
<p>-在尝试读取一个对象之前检查目标是否存在。</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">

if(settings.Contains(&quot;myemail&quot;))
{
...
}
</pre>
<p>博客园的博友aGan@net提出“最佳方式应该是TryGetValue，而不是检测Contains，前者性能更高”。</p>
<p>于是用Reflector看了一下微软的实现。</p>
<p>IsolatedStorageSettings.ApplicationSettings的Contains实际调用Dictionary&lt;TKey,TValue&gt;的ContainsKey方法：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">public bool ContainsKey(TKey key)
{
    return this.FindEntry(key) &gt;= 0;
}</pre>
<p><span id="more-330"></span></p>
<p>TryGetValue方法：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">public bool TryGetValue(TKey key, out TValue value)
{
    int index = this.FindEntry(key);
    if (index &gt;= 0)
    {
        value = this.entries[index].value;
        return true;
    }
    value = default(TValue);
    return false;
}</pre>
<p>TValue：</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">public TValue this[TKey key]
{
    get
    {
        int index = this.FindEntry(key);
        if (index &gt;= 0) return this.entries[index].value;
        return default(TValue);
    }
    set
    {
        this.Insert(key, value, false);
    }
}</pre>
<p>如果仅是判断是否存在的话，效率是一样的。<br />
  <br />但是如果判断存在后对Value进行操作，使用Contains方法的话，前后需要调用2次FindEntry方法，而用TryGetValue方法的话，只调用一次FindEntry方法，判断了是否存在同时取到了值，效率更高。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zdave.net/archives/330/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

