Edi Wang

Microsoft MVP for Azure

All Posts

Windows 10 UWP开发:支持异步的全局异常处理和堆栈信息

我们写UWP应用的时候难免遇到未处理的异常,不然你的应用就会在用户面前闪退,非常没有逼格。然而Windows.UI.Xaml.Application的UnhandledException事件里面有个巨坑,就是它不能处理async异步方法里的异常。注释里也没提到这回事: // // Summary: // Occurs when an exception can be handled by app code, as forwarded from a native-level // Windows Runtime error. Apps can mark the occurrence as handled in event data. public event UnhandledExceptionEventHandler UnhandledException; 处理全局异常确实 …
Windows Async Exception UWP

Windows 10 UWP开发:报错和反馈页面的实现

我的《上海轨道交通》应用里有个允许用户报告错误的页面,会把当前视图(xaml页面名称)、页面摘要、用户反馈的内容以及设备的软硬件信息生成邮件发给应用作者,界面如下: 生成的邮件如下: 问题描述:测试 (程序版本:3.2.0.0, 所在页面:StationDetail, 页面摘要:宜山路, 设备名:ISAAC, 操作系统:WINDOWS, SKU:Surface_Pro_3, 产品名称:Surface Pro 3, 制造商:Microsoft Corporation, 固件版本:, 硬件版本:) 要实现这样的报错页面非常容易 1.获取软硬件信息 我们要用的类是: Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation 比如获得设备名称,就可以直接: var deviceInfo = new
Windows UWP

Windows 10 UWP开发:如何本地化APP名称

我们在设计APP的时候,可能会考虑到不同国家和地区的用户使用,并在界面里针对不同的语言写资源文件做本地化。但是,如何让你的APP名称也本地化?比如在简体中文的系统上显示在程序列表里的是“调色板”,而在英文系统上显示的是“Color Palette”。 做法很简单,首先,和通常做本地化一样,你得有个"Strings\语言\Resources.resw"的文件夹结构。比如简体中文用的是“zh-CN”,美国英语是“en-US” 然后分别在resw文件里加一个key,比如AppName,然后针对不同语言填写不同的名称。这里简体中文是“调色板”,英语是“Color Palette” 最后这部最关键,打开你的Package.appxmanifest文件,把Display Name改成: ms-resource:AppName 现在,部署你的APP,就能看到不同的结果了。 补充:如果要让应用商店根 …
Windows UWP

How to save image to file in Windows 10 UWP

My UWP application "Shanghai Metro" has an option to allow user save the metro graph to local file system. The image file is located under project directory, "Assets\shanghaimetro-xl.jpg", and will ask the user to choose a location when saving the image. This is a very common functionality, it's also easy to achieve in UWP applications. The most easy way to do it is to use my library "Edi.UWP. …
Windows UWP

Windows 10 UWP开发:如何定时触发后台任务

今天在爆UWP的定时后台任务,坑有点多。有的坑在很多网上的文章里都没提到,非常的坑。刚刚开荒成功了,把经验写出来分享: 1. 写一个后台任务的类,继承IBackgroundTask接口 通常,在设计应用程序结构的时候,我们会建类库项目(Class Library)放这些类。比如 FarkBackgroundTask.Core 因为是UWP工程,所以建的类库也要是Universal Windows的。注意,这里我们已经埋下了一个巨坑,稍后会解释。 我们的类代码如下: public class SayFarkTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { Debug.Write("================ Fark the
Windows Timer UWP Task

Windows 10 UWP开发:如何弹出消息通知

在UWP的App中,弹出消息通知的方法和WinRT一致,注意是App内的消息通知(toast notification)而不是从服务器端推送的通知。主要有几个步骤: 1. 创建XML定义 // 1. create element ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); 这里面的消息模板有好几种: // // Summary: // 指定要在消息通知中使用的模版。 [ContractVersion(typeof(UniversalApiContract), 65536)] public enum …
Windows UWP

Windows 10 UWP Development: How to Implement WP8's Pivot Effect

The animation effect of the Pivot widget in UWP is different from the previous Pivot in Windows 8 and Windows Phone 8, when switching PivotItem, the header of the currently selected Item will not run to the first one, but simply highlight the current Tab like a Tab tab. Personally, I like Windows 8's Pivot, which is like this GIF (which is a UWP app I'm working on). If you also like the traditional style of Pivot, you can refer to the following methods.
Windows UWP

How to Redirect Old Domain URL to New Domain in IIS

When you change the domain name for your website, you are definitely going to solve the migration problem. You cannot just stop DNS on your old domain, because this will cause your indexed pages to be deleted by search engines. The correct way is to tell the search engine that you have a new domain name now, which is when the user accesses an old URL, redirect it to the new URL. Take my blog …
IIS URL URL Rewrite

Windows 10 UWP开发:自定义标题栏

UWP和WPF以及以前Windows 8.1的WinRT应用有些不一样的地方。首先就是标题栏,以前Windows 8.1的应用都是全屏的,没有标题栏,Windows 10里面应用可以窗口化运行,所以我们也能够利用标题栏做一些定制。本文针对初学者,可能写的比较啰嗦。 一、首先是最基本的,如何改变标题栏及按钮的颜色 标题栏的对象位于Windows.UI.ViewManagement.ApplicationView类里,有个属性是 public ApplicationViewTitleBar TitleBar { get; } 为了能够访问这个属性,我们需要先取得当前应用窗口的view: var view = ApplicationView.GetForCurrentView(); 拿到view对象后,就能对TitleBar属性操作了,标题栏的活动和非活动状态的前景色和背景色可以这样设置, …
Windows UWP

Fix Visual Studio 2015 Razor Editor Blow Up

Visual Studio 2015 has been RTM for one month. However, it blows up very often, such as Razor editor. When I try to open any .cshtml file, it blows up with this error, then the syntax highlight is gone. I tried to uninstall all add-on, even repair install VS2015 can't get it working. The detailed error message is: System.Reflection.TargetInvocationException: Exception has been thrown by the …
Razor