鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > .net技术 > WinRT/Metro > >

选取器: CachedFileUpdater(缓存文件更新程序)

来源:互联网 作者:佚名 时间:2013-05-23 12:03
重新想象 Windows 8 Store Apps (28) - 选取器: CachedFileUpdater(缓存文件更新程序)Posted on [源码下载] 重新想象 Windows 8 Store Apps (28) - 选取器: CachedFileUpdater(缓存文件更新程序) 作者:webabcd 介绍 重新想象 Windows 8 Store Apps 之选

重新想象 Windows 8 Store Apps (28) - 选取器: CachedFileUpdater(缓存文件更新程序) Posted on

[源码下载]


重新想象 Windows 8 Store Apps (28) - 选取器: CachedFileUpdater(缓存文件更新程序)



作者:webabcd


介绍
重新想象 Windows 8 Store Apps 之 选取器

  • CachedFileUpdater - 缓存文件更新程序


  • 示例
    一、首先新建一个 Windows 应用商店项目,使其作为缓存文件更新程序

    1、 打开一个文件,并关联到 CachedFileUpdater
    CachedFileUpdaterProvider/MyOpenPicker.xaml

    <Page x:Class="CachedFileUpdaterProvider.MyOpenPicker" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:CachedFileUpdaterProvider" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable

    CachedFileUpdaterProvider/MyOpenPicker.xaml.cs

    /* * 打开一个文件,并关联到 CachedFileUpdater * * 1、在 Package.appxmanifest 中新增一个“文件打开选取器”声明,并做相关配置 * 2、在 App.xaml.cs 中 override void OnFileOpenPickerActivated(FileOpenPickerActivatedEventArgs args),如果 app 是由文件打开选取器激活的,则可以在此获取其相关信息 */ using System; using Windows.ApplicationModel.Activation; using Windows.Storage; using Windows.Storage.Pickers.Provider; using Windows.Storage.Provider; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; namespace CachedFileUpdaterProvider { MyOpenPicker : Page { private FileOpenPickerUI _fileOpenPickerUI; public MyOpenPicker() { this.InitializeComponent(); } OnNavigatedTo(NavigationEventArgs e) { var args = (FileOpenPickerActivatedEventArgs)e.Parameter; _fileOpenPickerUI = args.FileOpenPickerUI; _fileOpenPickerUI.Title = ; } btnPickCachedFileLocal_Click_1(object sender, Windows.UI.Xaml.RoutedEventArgs e) { StorageFile file = , CreationCollisionOption.ReplaceExisting); ; await FileIO.WriteTextAsync(file, textContent); /* * 设置 CachedFile,即将文件关联到 CachedFileUpdater * SetUpdateInformation(IStorageFile file, string contentId, ReadActivationMode readMode, WriteActivationMode writeMode, CachedFileOptions options); * file - 与 CachedFileUpdater 关联的文件 * contentId - 与 CachedFileUpdater 关联的文件标识 */ CachedFileUpdater.SetUpdateInformation(file, , ReadActivationMode.BeforeAccess, WriteActivationMode.NotNeeded, CachedFileOptions.RequireUpdateOnAccess); lblMsg.Text = + file.Name; AddFileResult result = _fileOpenPickerUI.AddFile(, file); } btnPickCachedFileRemote_Click_1(object sender, Windows.UI.Xaml.RoutedEventArgs e) { StorageFile file = , CreationCollisionOption.ReplaceExisting); ; await FileIO.WriteTextAsync(file, textContent); /* * 设置 CachedFile,即将文件关联到 CachedFileUpdater * SetUpdateInformation(IStorageFile file, string contentId, ReadActivationMode readMode, WriteActivationMode writeMode, CachedFileOptions options); * file - 与 CachedFileUpdater 关联的文件 * contentId - 与 CachedFileUpdater 关联的文件标识 */ CachedFileUpdater.SetUpdateInformation(file, , ReadActivationMode.NotNeeded, WriteActivationMode.AfterWrite, CachedFileOptions.RequireUpdateOnAccess); lblMsg.Text = + file.Name; AddFileResult result = _fileOpenPickerUI.AddFile(, file); } } }


    2、 开发自定义缓存文件更新程序
    CachedFileUpdaterProvider/MyCachedFileUpdater.xaml

    <Page x:Class="CachedFileUpdaterProvider.MyCachedFileUpdater" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:CachedFileUpdaterProvider" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable

    CachedFileUpdaterProvider/MyCachedFileUpdater.xaml.cs

    网友评论
    <