Windows Development 86 UWP, WPF, and Other Windows Development Techniques


Read System Certificates in UWP

In Windows, we can view and manage the certificates using certmgr.msc, which is a system management console included in Windows itself.  However, what if we want to view the certificates information in an UWP app? Here is the answer. First thing first, the method I use does not apply to UWP only. In fact it is from a WPF app I wrote. As Microsoft released .NET Standard 2.0, which allows me to...

UWP

Send Feedback in UWP Apps by Windows 10 Feedback Hub

After our app has been put on Microsoft Store, there are a lot of ways to get users to send feedback, such as email, store reviews, or even write our own API collect feedback. But in fact, Windows 10 Feedback Hub can also be used to send feedbacks for our own Apps. Those who are familiar with Windows Insider know that when Windows 10 is installed, the system has a Feedback Hub, which is usually u...

UWP

UWP应用中自定义亚克力材质

Windows 10 秋季更新(Build 16299)中引入了亚克力材质,这是一种类似于Windows 7窗口磨砂玻璃效果的Brush。 很多Windows自带的应用,比如计算器,就引入了这样的设计。然而,系统自带的画刷有时候无法满足我们自己设计App的需求,特别是在Windows决定不渲染亚克力效果的时候,比如设备在低电量模式下运行,或者窗口非激活状态下,很多系统默认画刷会让我们App的界面变的很丑。 比如,这是正常的亚克力效果: 窗口inactive的时候竟然变成了: 这时候就需要我们自定义亚克力的参数,并且定义fall back的配色方案。比如我的"Character Map UWP",就是使用自定义亚克力的一个例子。 正常状态显示自定义透明度的黑色: 全屏或者inactive状态,显示系统主题色: 这样的效果,是通过自定义AcrylicBrush...

UWP

在UWP应用中响应键盘快捷键

一个优秀的Windows应用不仅要面向鼠标、触屏用户,同时还需要兼顾到键盘操作,特别是一些常见的快捷键,比如撤销(CTRL + Z),以提供全面的用户体验。 那么在UWP里如何定义键盘快捷键呢,以我的《描图》APP为例,我需要实现撤销的快捷键(CTRL + Z)。首先,我们需要定义快捷键的操作,是用户当前焦点在哪个控件上的,如果需要整个应用界面都监听键盘操作,那么这个UI控件就是XAML页面最外层的容器:GRID 所以,首先我们在Page下面的第一级Grid,也就是最外层容器上,定义2个事件:KeyDown和KeyUp,如下: 接下来,因为我们想操作的快捷键(CTRL + Z)是个组合键,所以我们需要知道用户是否按同时按下了CTRL键和Z键,为此,我们要定义一个布尔变量用来标识CTRL是否已被按下的状态: private bool _isCtrlKeyPressed; 然后定...

UWP

Show Confirm Dialog When User Close UWP App

When our UWP Application deal with user data in it, e.g. like drawings or documents, we usually want to make sure user won't close the App by accident and lose their work. Just like what you see in a Office application, it will ask you if you want to save your document before close the App. For a long time, UWP could not do that in a normal way. Because it is not a general public API and it is st...

UWP

Windows 10 秋季更新上用编程方式重启UWP应用

有时候,我们的UWP应用会要求用户重启,以应用一些设置。通常情况下,用户只能手工关闭App并再次打开完成重启的步骤。其实,在Windows 10秋季更新里,开发者已经可以通过编程方式,让用户一键完成自动重启App的工作。 比如我的“Character Map UWP”这个应用,在用户更改设置后,需要重启生效。那么第一步,就是在设置页面加一个重启按钮“Restart Now”: 然后,我们需要通过秋季更新中的全新牛逼API RequestRestartAsync(String) 来完成重启。 这个API的签名如下: public static IAsyncOperation RequestRestartAsync(String launchArguments) 如果只是为了完成重启,不需要参数,那么lauchArguments是可以留空的。 所以,在我的这个例子里,最简单...

UWP

Automatically Set Text Color on Accent Background in UWP

Windows 10 allows users to set accent color for the system, and in UWP apps, we usually honor those settings by using XAML pre-defined resource keys like {ThemeResource SystemControlBackgroundAccentBrush}. But regardless of how the user set default app mode to dark or light, when we apply text on accent colors, it may have some problems. For example, when the App is in light mode, the default...

XAML UWP

Configure VSTS Build for UWP Apps

UWP Apps usually require a lot of time to compile a "release" package for submitting to Windows Store, and if you are working in a team, TFS/VSTS can help your team ensure that each check-in has a success build, and make it easier for deployment and testing. Let's see a basic example of how to setup a CI build for a UWP App on VSTS. Important Pre-condition: Before you do that, please ensure...

UWP VSTS

Windows 10 UWP: Switching Languages in Your App

By default, a UWP App's UI language is automatically fits the system current language settings. However, what if the user need the ability to set a particular UI language just for your App without having to change system language? In my App, I supports Simplified Chinese and English. The user can override the system language in App's settings page: So how to do it? First, you need to have res...

UWP Localization

Windows 10 UWP: How to Read and Save Settings Easily

In the UWP Application model, reading and saving settings are very similar to WinRT API. The class we are using is ApplicationData.Current.LocalSettings It is using key-value-pair to store settings. LocalSettings will stay on the user's current computer, and not being synced with thier Microsoft account. The API to save settings is: LocalSettings.Values[key] = value; To read settings:  if (Lo...

Windows 10 UWP