与众不同 windows phone (28) - Feature(特性)之手机方向, 本地化, 应用程序的试用体验, 系统主题资源, 本地数据的加密解密

简介: 原文:与众不同 windows phone (28) - Feature(特性)之手机方向, 本地化, 应用程序的试用体验, 系统主题资源, 本地数据的加密解密[索引页][源码下载] 与众不同 windows phone (28) - Feature(特性)之手机方向, 本地化, 应用程序的试用...
原文: 与众不同 windows phone (28) - Feature(特性)之手机方向, 本地化, 应用程序的试用体验, 系统主题资源, 本地数据的加密解密

[索引页]
[源码下载]


与众不同 windows phone (28) - Feature(特性)之手机方向, 本地化, 应用程序的试用体验, 系统主题资源, 本地数据的加密解密



作者:webabcd


介绍
与众不同 windows phone 7.5 (sdk 7.1) 之特性

  • 手机方向
  • 本地化
  • 应用程序的试用体验
  • 系统主题资源
  • 本地数据的加密解密



示例
1、演示如何响应手机的方向变化
Orientation.xaml

<phone:PhoneApplicationPage 
    x:Class="Demo.Feature.Orientation"
    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">

    <Grid x:Name="LayoutRoot" Background="Transparent">
    
        <TextBlock Text="改变手机方向,以查看演示效果" />
        
    </Grid>

</phone:PhoneApplicationPage>

Orientation.xaml.cs

/*
 * 演示如何捕获手机方向改变的事件 
 * 
 * PhoneApplicationPage - 页面
 *     SupportedOrientations - 支持的方向(Microsoft.Phone.Controls.SupportedPageOrientation 枚举)
 *         Portrait(竖), Landscape(横), PortraitOrLandscape(横竖)
 *     Orientation - 当前的方向(Microsoft.Phone.Controls.PageOrientation 枚举)
 *         None, Portrait, Landscape, PortraitUp, PortraitDown(目前不支持), LandscapeLeft(PortraitUp 逆时针转到 Landscape), LandscapeRight(PortraitUp 顺时针转到 Landscape)
 *     OrientationChanged - 方向改变后触发的事件(事件参数:OrientationChangedEventArgs)
 *     
 * OrientationChangedEventArgs
 *     Orientation - 当前的页面方向
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace Demo.Feature
{
    public partial class Orientation : PhoneApplicationPage
    {
        public Orientation()
        {
            InitializeComponent();

            this.SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
            this.OrientationChanged += new EventHandler<OrientationChangedEventArgs>(Orientation_OrientationChanged);
        }

        void Orientation_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {
            if ((e.Orientation & PageOrientation.Portrait) == (PageOrientation.Portrait))
            {
                MessageBox.Show("竖放");
            }
            else
            {
                MessageBox.Show("横放");
            }
        }
    }
}


2、演示如何实现程序的本地化
Localization.xaml

<phone:PhoneApplicationPage 
    x:Class="Demo.Feature.Localization"
    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">

    <phone:PhoneApplicationPage.Resources>
        <!--
            注:AppResources 里的类和构造函数需要 public 的要手动改成 public
        -->
        <resources:AppResources xmlns:resources="clr-namespace:Demo.Resources" x:Key="MyLocalization" />
    </phone:PhoneApplicationPage.Resources>
    
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <StackPanel Orientation="Vertical">

            <TextBlock Name="lblMsg" />

            <!--
                xaml 方式应用本地化
            -->
            <TextBlock Text="{Binding Path=Software, Source={StaticResource MyLocalization}}" />

        </StackPanel>
    </Grid>

</phone:PhoneApplicationPage>

Localization.xaml.cs

/*
 * 演示如何本地化应用程序,相关资源文件在 Resources 目录下
 * 
 * 注:本地化应用程序标题(标题分为两种:应用程序列表中的标题和“磁贴”上的应用程序标题,它们可以不同)请参看 http://msdn.microsoft.com/en-us/library/ff967550(v=vs.92).aspx
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using Demo.Resources;

namespace Demo.Feature
{
    public partial class Localization : PhoneApplicationPage
    {
        public Localization()
        {
            InitializeComponent();

            // 代码方式应用本地化
            lblMsg.Text = AppResources.Network;
        }
    }
}


3、演示如何提供支持试用体验的应用程序
TrialExperience.xaml

<phone:PhoneApplicationPage 
    x:Class="Demo.Feature.TrialExperience"
    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">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <StackPanel Orientation="Vertical">
            
            <Button Name="btnTrial" Content="试用版可用的功能" Click="btnTrial_Click" />

            <Button Name="btnNormal" Content="正式版里才有的功能" Click="btnNormal_Click" />

            <Button Name="btnBuy" Content="购买正式版" Click="btnBuy_Click" />

        </StackPanel>
    </Grid>

</phone:PhoneApplicationPage>

TrialExperience.xaml.cs

/*
 * 演示如何在收费应用程序中加入试用体验
 * 
 * LicenseInformation - 应用程序的许可证信息
 *     IsTrial() - 是否是试用版
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using Microsoft.Phone.Marketplace;
using Microsoft.Phone.Tasks;

namespace Demo.Feature
{
    public partial class TrialExperience : PhoneApplicationPage
    {
        private static LicenseInformation _licenseInfo = new LicenseInformation();

        private static bool _isTrial = true;

        public TrialExperience()
        {
            InitializeComponent();

            // 检查许可证,仅为测试用,实际项目中最好将此逻辑放到 Application_Launching 和 Application_Activated 中
            CheckLicense();
        }

        private void CheckLicense()
        {
#if DEBUG
            // 仅调试用,强行指定程序为试用版
            _isTrial = true;
#else
            // 获取当前安装到设备的版本是否为试用版
            _isTrial = _licenseInfo.IsTrial();
#endif
            
            // 如果是试用版则禁用正式版的功能
            if (_isTrial)
                btnNormal.IsEnabled = false;
        }

        private void btnTrial_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("试用版可用的功能");
        }

        private void btnNormal_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("正式版里才有的功能");
        }

        private void btnBuy_Click(object sender, RoutedEventArgs e)
        {
            // 购买的话,直接打开应用程序在商店的详细页就好
            MarketplaceDetailTask marketPlaceDetailTask = new MarketplaceDetailTask();
            marketPlaceDetailTask.Show();
        }
    }
}


4、演示如何使用系统主题资源
ThemeResources.xaml

<phone:PhoneApplicationPage 
    x:Class="Demo.Feature.ThemeResources"
    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">

    <Grid x:Name="LayoutRoot" Background="Transparent">

        <TextBlock Text="使用系统主题资源" Style="{StaticResource PhoneTextExtraLargeStyle}" />

        <HyperlinkButton Content="全部系统主题资源" NavigateUri="http://msdn.microsoft.com/en-us/library/ff769552(v=vs.92)" TargetName="_blank" />
        
    </Grid>

</phone:PhoneApplicationPage>


5、演示如何实现本地数据的加密解密
EncryptData.xaml

<phone:PhoneApplicationPage 
    x:Class="Demo.Feature.EncryptData"
    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">

    <Grid x:Name="LayoutRoot" Background="Transparent">

        <TextBlock Text="注:不同的应用程序有不同的密钥" />
        
    </Grid>

</phone:PhoneApplicationPage>

EncryptData.xaml.cs

/*
 * 演示如何对数据做加密解密
 * 
 * ProtectedData - 用于加密解密数据
 *     Protect() - 加密数据
 *     Unprotect() - 解密数据
 * 
 * 注:不同的应用程序有不同的密钥,所以本示例的加密解密仅针对同一应用程序有效。应用场景为:本地数据的加密解密
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using System.Security.Cryptography;
using System.Text;

namespace Demo.Feature
{
    public partial class EncryptData : PhoneApplicationPage
    {
        private string _base64 = "";

        public EncryptData()
        {
            InitializeComponent();

            EncryptDemo();

            DecryptDemo();
        }

        private void EncryptDemo()
        {
            byte[] plainText = Encoding.UTF8.GetBytes("webabcd");
            byte[] protectedData = ProtectedData.Protect(plainText, null);

            _base64 = Convert.ToBase64String(protectedData);

            MessageBox.Show("字符串“webabcd”加密且base64后的数据:" + Environment.NewLine + _base64);
        }

        private void DecryptDemo()
        {
            byte[] protectedData = Convert.FromBase64String(_base64);
            byte[] plainText = ProtectedData.Unprotect(protectedData, null);

            MessageBox.Show("解密后的数据:" + Environment.NewLine + Encoding.UTF8.GetString(plainText, 0, plainText.Length));
        }
    }
}



OK
[源码下载]

目录
相关文章
|
计算机视觉 Windows Python
windows下使用python + opencv读取含有中文路径的图片 和 把图片数据保存到含有中文的路径下
在Windows系统中,直接使用`cv2.imread()`和`cv2.imwrite()`处理含中文路径的图像文件时会遇到问题。读取时会返回空数据,保存时则无法正确保存至目标目录。为解决这些问题,可以使用`cv2.imdecode()`结合`np.fromfile()`来读取图像,并使用`cv2.imencode()`结合`tofile()`方法来保存图像至含中文的路径。这种方法有效避免了路径编码问题,确保图像处理流程顺畅进行。
3083 1
|
数据采集 人工智能 编解码
算法系统协同优化,vivo与港中文推出BlueLM-V-3B,手机秒变多模态AI专家
BlueLM-V-3B是由vivo与香港中文大学共同研发的多模态大型语言模型,专为移动设备优化。它通过算法和系统协同优化,实现了高效部署和快速生成速度(24.4 token/s),并在OpenCompass基准测试中取得优异成绩(66.1分)。模型小巧,语言部分含27亿参数,视觉编码器含4000万参数,适合移动设备使用。尽管如此,低端设备可能仍面临资源压力,实际应用效果需进一步验证。论文链接:https://arxiv.org/abs/2411.10640。
899 9
|
Web App开发 存储 安全
微软警告数百万Windows用户:切勿冒险丢失所有数据
微软警告数百万Windows用户:切勿冒险丢失所有数据
微软警告数百万Windows用户:切勿冒险丢失所有数据
|
缓存 NoSQL Linux
【Azure Redis 缓存】Windows和Linux系统本地安装Redis, 加载dump.rdb中数据以及通过AOF日志文件追加数据
【Azure Redis 缓存】Windows和Linux系统本地安装Redis, 加载dump.rdb中数据以及通过AOF日志文件追加数据
685 1
【Azure Redis 缓存】Windows和Linux系统本地安装Redis, 加载dump.rdb中数据以及通过AOF日志文件追加数据
|
数据库 数据安全/隐私保护 Windows
Windows远程桌面出现CredSSP加密数据修正问题解决方案
【10月更文挑战第30天】本文介绍了两种解决Windows系统凭据分配问题的方法。方案一是通过组策略编辑器(gpedit.msc)启用“加密数据库修正”并将其保护级别设为“易受攻击”。方案二是通过注册表编辑器(regedit)在指定路径下创建或修改名为“AllowEncryptionOracle”的DWORD值,并将其数值设为2。
13635 3
|
移动开发 Android开发 数据安全/隐私保护
移动应用与系统的技术演进:从开发到操作系统的全景解析随着智能手机和平板电脑的普及,移动应用(App)已成为人们日常生活中不可或缺的一部分。无论是社交、娱乐、购物还是办公,移动应用都扮演着重要的角色。而支撑这些应用运行的,正是功能强大且复杂的移动操作系统。本文将深入探讨移动应用的开发过程及其背后的操作系统机制,揭示这一领域的技术演进。
本文旨在提供关于移动应用与系统技术的全面概述,涵盖移动应用的开发生命周期、主要移动操作系统的特点以及它们之间的竞争关系。我们将探讨如何高效地开发移动应用,并分析iOS和Android两大主流操作系统的技术优势与局限。同时,本文还将讨论跨平台解决方案的兴起及其对移动开发领域的影响。通过这篇技术性文章,读者将获得对移动应用开发及操作系统深层理解的钥匙。
756 12
|
Oracle 关系型数据库 数据库
[windows]远程桌面失败提示CredSSP加密修正
[windows]远程桌面失败提示CredSSP加密修正
3741 6
|
存储 缓存 安全
硬盘数据恢复:恢复硬盘数据的9个实用方法(Windows版)
无论是工作文档、家庭照片,还是其他珍贵的数字资产,数据丢失总是一件让人头疼的事情。然而,当硬盘发生问题时,不必过于慌张——只要正确应对,许多数据都可以被成功恢复。本文将从常见数据丢失原因到具体恢复方法,为您提供全面的硬盘数据恢复指导。
|
存储 NoSQL Java
使用redis进行手机验证码的验证、每天只能发送三次验证码 (redis安装在虚拟机linux系统中)
该博客文章展示了如何在Linux虚拟机上使用Redis和Jedis客户端实现手机验证码的验证功能,包括验证码的生成、存储、验证以及限制每天发送次数的逻辑,并提供了测试结果截图。
使用redis进行手机验证码的验证、每天只能发送三次验证码 (redis安装在虚拟机linux系统中)
|
编解码 开发工具 C#
Windows电脑如何启动RTSP服务实现本地摄像头数据共享
本文介绍如何利用大牛直播SDK中的轻量级RTSP服务,在Windows平台上轻松采集摄像头数据并生成本地RTSP流。通过SDK提供的SmartPublisherDemo工具,用户能简便地选择摄像头、配置分辨率与帧率,并启动RTSP服务。此外,还支持音频采集、多端口服务以及动态水印等功能。生成的RTSP URL可用于其他终端拉流播放,无需额外部署服务器。该服务适配多种应用场景,如安防监控、电子教室等,并兼容Windows 7及以上版本。对于希望集成此功能的开发者,SDK提供了C++及C#接口,并支持多种编译模式。
1581 0