Edi Wang

All Posts 297


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

在 Windows 10 秋季更新上安装 Linux 子系统

纳德拉说,微软爱Linux。这真的不只是说说,居然还做到了!最近的Windows 10 v1709 秋季更新里,Linux子系统的支持得到了相当大的改进,只需要2步就可以安装使用Linux子系统! 那么,在Windows 10秋季更新上安装Linux究竟有多简单呢? 那么,在Windows 10秋季更新上安装Linux究竟有多简单呢? 1. 启用 Windows Subsystem for Linux 由于控制面板被故意藏起来了,现在打开经典“添加删除程序”界面的最快方式是运行 appwiz.cpl 然后勾选“Windows Subsystem for Linux” 安装完后重启机器。 2. 在应用商店安装你需要的Linux版本 搜索"Linux"即可 目前在应用商店中的有3种Linux:Ubuntu 16.04及openSUSE的2个版本,这次我选择Ubun...

Windows Linux

Use ICMP Ping in .NET Core 2.0

In classic .NET Framework applications, we have used System.Net.NetworkInformation.Ping class to Ping a host address. This API is not included by default in .NET Core, even in version 2.0. Here is how to do it in a .NET Core way. First, we need to reference a package System.Net.Ping Install-Package System.Net.Ping This will give us the same API set as .NET Framework. Then, in your .NET Core...

.NET Core Ping ICMP

Use NLog in ASP.NET Core 2.0

Recently I am porting a classic ASP.NET MVC 5 project to .NET Core 2.0, in order to run it on Linux. One of the parts that has differences between .NET Fx and .NET Core is logging. I choose NLog as my logging providor, let's see how to port this to .NET Core. 1. Migrating Configuration File First, let's see the .NET Framework version of nlog.config.  This basic...

.NET Core NLog

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

Get Client IP Address in ASP.NET Core 2.0

In classic ASP.NET we used to get client IP Address by Request.UserHostAddress. But this does not apply to ASP.NET Core 2.0. We need a different way to retrieve HTTP Request information. 1. Define a variable in your MVC controller private IHttpContextAccessor _accessor; 2.  DI into the controller's constructor public SomeController(IHttpContextAccessor accessor) { _accessor = accessor;...

ASP.NET .NET Core

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

Windows 10 UWP: How to Debug OnFileActivated Launch Failure

Today I am working on my Image Portray App, and I get my code blown up. The problem is, when the App is already started, it can open .ink file with double click from a file. But when the App is not launched, opening a .ink file to start the App will make it crash. As other UWP that supports file type association, I also use OnFileActivated event to launch my App. This kind of problem could not be...

Debug Visual Studio UWP