Edi Wang

Microsoft MVP for Azure

All Posts

Apply Keyboard Short Cuts in UWP

A greate Windows App requires not only mouse and touch screen friendly, but also need to think about keyboards. Especially for some common short cuts, like Undo (CTRL + Z). So that the App can provide better user experience.  So how can we define short cut keys in UWP? Take my App Tracing as example, I need to implement short cuts for Undo (CTRL + Z). First, we need to consider which Control is …
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 …
UWP

Install Linux Subsystem on Windows 10 Fall Creators Update

In the recent Windows 10 v1709 Fall Creators Update, the Windows subsystem for Linux has been improved a lot. Let's see how easy it is now to install Linux on Windows. 1. Enable Windows Subsystem for Linux Because the classic control panel has been hidden, now the quickest way to access Programs and Features is to run appwiz.cpl And then check "Windows Subsystem for Linux" under "Turn Windows …
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 code, …
.NET ICMP

Use NLog in ASP.NET Core 2.0

There's official update for NLog targeting ASP.NET Core 2.x, for the latest methods please refer to https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2 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 …
.NET 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.x

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; …
.NET ASP.NET

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 that …
UWP Azure DevOps

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 …
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 ( …
Windows UWP