Edi Wang

.NET and Azure Developer

Posts in 2016

How to Remove ListView Default Selection in Windows 10 UWP

A lot of people including me has encounter a problem where on UWP apps, if a ListView control is being data binded, it will get a default selected item like this: It not only will display as selected item, it also fires SelectionChanged event. However, if we want to make ListView clickable, a popular way is to write the SelectionChanged event handler like this: private void StationsList_ …
Windows UWP

How to make a modal progress dialog in Windows 10 UWP

Windows 10 Mobile上的文件管理器有这样一个进度指示器,它是一个模态框,不带任何按钮,只有进度条和文本: 今天我琢磨了很久,绕了一些弯路,发现其实要做一个这样的模态进度指示器很简单。只要用ContentDialog就行。 平时我们用ContentDialog有些思维定势,就觉得这个对话框一定要提供按钮给用户操作。其实它是可以不设置任何按钮的,这样就有了初步的雏形: XAML C# private async void BtnSitAndRelax_OnClick(object sender, RoutedEventArgs e) { // show progress await ModalProgressDig.ShowAsync(); } …
Windows UWP

UWP App for the Raspberry Pi Azure Surveillance Camera

I wrote a post about Raspberry Pi Surveillance Camera with Linux and Azure, it was using an ASP.NET website for displaying the photos. I made an UWP client App these days, you can download from here https://www.microsoft.com/store/apps/9nblgggzfnv0 (Because WP is already finished, so I don't provide Windows 10 Mobile package) It doesn't allow upload photos, because the photos should all come …
MVVM Binding

Read AppSettings in ASP.NET Core 2.x

Today, I was rewriting an old ASP.NET MVC5 Demo project to ASP.NET Core, and found that the way we used to read Web.config by ConfigurationManager.AppSettings[] is no longer working. .NET Core has many new ways to achieve this. I picked one that suitable for my project. Here is how I do it. The Classic ASP.NET Code web.config Controller private static CloudBlobContainer GetBlobContainer() …
.NET ASP.NET

Windows 10 UWP开发:拼音首字母分组如何去掉“拼音”前缀并支持切换系统语言

Windows 10里面有个脑残设计,就是系统默认的CharacterGroupings类型在中文版系统上会产生除了A-Z字母以外的带“拼音”前缀的另外24个分组。比如开屎菜单里就是这样: 如果我们用这个CharacterGroupings类型去创建带分组的ListView,就会变成这样: 更蛋疼的是,如果用户的系统是英文语言的,他就会发现分组变成空白了,没有任何数据。用户不知道这是微软干的,又得给我们的APP打1星,还要骂我们傻逼。 今天经过研究,终于把这个问题给解决了,不仅去掉了“拼音”前缀,也不用担心用户系统是什么语言的,都能正常显示分组列表。 我们先看看原来的代码。 public class AlphaKeyGroup<T> : List<T> { const string GlobeGroupKey = "?"; …
Windows UWP

Sharing Images in Windows 10 UWP

Starting from Windows 8, one big feature for Windows Store Apps is to share data using Charm Bar across Apps. Although the Charm Bar is removed in Windows 10, but the API for sharing is still in the fight.  For example, in my "Image Portray" App, I can share ink to OneNote or Outlook. Today, I added same capability for my "Shanghai Metro" App. Here's how to do it. First, to share data across …
Windows UWP

Raspberry Pi Surveillance Camera with Linux and Azure

Because Windows 10 IoT Core is not supporting Pi Camera, I can only use Linux instead. These days, I made a surveillance camera, the functionality is simple, when a person passed by the camera, it will take a picture and upload to Microsoft Azure Storage. It also got a website to remotely view the photos. 1. Hardware A PIR Sensor, a Pi Camera, a couple of jump wires. Connect the Singal port of …
Azure IoT Raspberry Pi Linux Python

Uploading PiCamera images to Azure

Recently Windows 10 IoT Core Build 14393 is coming, but still without PiCamera support, WTF. So I can only choose Linux for my project. When I was using Windows, I use C# + Azure SDK to upload photos to Microsoft Azure. So how to do it on Linux? After some research, here's how to do it. My system is Raspbian Linux. First, we need to install Azure SDK in SSH Terminal: sudo pip install --pre azure …
Azure Raspberry Pi Linux Python

Raspberry Pi 3 and Windows 10 IoT Core Basics

最近有时间,总结了一下关于树莓派3及Windows 10 IoT的基础知识。适合没有接触过硬件但有一定编程经验的读者入门。我自己刚刚买树莓派的时候花了很长时间入门,搞清楚各种概念和属于。很多网上的帖子都是分散在各个角落的,并且是英文的,有些还是过时的,有些是爆的,所以我觉得有必要总结一篇基础入门帖子。这篇文章讲的都是抛砖引玉的概念,并不包括End-To-End的Case,想要做一个完整实验的文章,请看我博客的物联网开发系列文章:http://edi.wang/category/list/iot  如果有错误和补充,欢迎在评论里指出。 一、树莓派3 树莓派是基于ARM芯片的卡片电脑,大小和一张信用卡一样。今年推出了第三代,集成了板载蓝牙和WIFI。之前的树莓派1和2都是需要用USB WIFI和蓝牙实现的,所以你要是购买树莓派,买3是最方便的,可以省去USB WIFI和蓝牙的配件。并且 …
IoT Raspberry Pi

How to use Windows RDP to connect Raspbian Linux

Because Windows 10 IoT Core is not yet ready to replace Raspbian, in some case, we have to use Linux. The remote operation on Linux is usually done by SSH. If you want remote desktop like the one on Windows. There are two options: tightvnc or xrdp. I used to  use tightvnc, it does not have any problem with daily use. But I have to install a tightvnc client on my PC. However, XRDP can be supported …
IoT Raspberry Pi Linux Remote Desktop

Windows 10 IoT: How to Drive an SSD1306 I2C Display

I bought a 128x64 0.96 inch OLED display, like this one: The driver chip for this screen is called SSD 1306, typically, this chip will have 2 layouts, SPI or I2C. However, the examples fo how to drive I2C with SSD 1306 is very rare, and they run on Raspbian not Windows. Luckly, with the help from a Microsoft Staff in US, we finally got the code to run the screen on Windows 10 IoT Core. 1. …
IoT Raspberry Pi

315MHz Remote Door Control by Windows 10 IoT

这几天我用树莓派实现了一个模仿车库遥控门的设备,分享给大家。(优酷视频 http://v.youku.com/v_show/id_XMTU3ODk1NDY2OA==.html )   一、遥控模块 首先介绍一下我用的遥控器和接收板,这种遥控模块在中国随处可以买到,基本都是长这样的。很多卷帘门、车库门都是用这种遥控模块的。做无线电实验购买的是非锁的版本,注意最好同时购买天线。天线用的是50欧姆单芯导线,其实就是个铜丝,注意购买时候要看好频率,中国大陆的无线电许可频率是315MHz,国外也有用443MHz的,我买的遥控器是315MHz。注意遥控器发射频率和接收频率要匹配就行。遥控接收端芯片是PT2272-M4,M4的意思是点动模式,即按住遥控器按钮输出高电平,松开停止输出。遥控板的ANT端焊接天线,方向要是竖直向上的(相对你的设备)。 遥控板的接口有7个: 接口 含义 GND 电源负 …
Windows IoT Raspberry Pi

Reed Controlled Light by Windows 10 IoT Core

Reed switch is an electronic component to connect / disconnect the switch by magnetic field. When it touchs magnetic field, the two iron sheets inside the tube will clip together, so the switch is connected.  The application of Reed Swith: Door light controller: When you open the door, turn the light on. When you close the door, turn off the light. This is simply install a reed switch on your …
Windows IoT Raspberry Pi

74HC595 4 Digits LED Tube with Windows 10

One of the commonly used LED Tube driver chip is 74HC595, by using the Chip, you can save GPIO ports. I bought an LED Tube with 595 chip, it only needs 3 GPIO ports to display 4 digits. However, there is no existing posts about how to drive the 74HC595 LED Tube from Windows 10. So, I can only try for myself. …
Windows IoT Raspberry Pi

Using stepper motor in Windows 10 IoT Core

如果你需要精确控制设备的转动角度,普通电机是做不到的,通常我们会选用步进马达。比如28BYJ-48这个型号的,很容易买到。 步进马达得配合驱动板使用,最常用的是ULN2003芯片的驱动板,就像下图。不过注意,你买到的驱动板长相可能不太一样,不过没关系,只要芯片上写的是ULN2003,就可以使用,它们的接口都是一样的。关于步进马达的原理,可以看这篇: https://en.wikipedia.org/wiki/Stepper_motor  拿到驱动板和步进马达后,将马达插入驱动板的白色插槽中,这个接口有防呆设计,所以不会插反。 关于Windows 10 IoT如何驱动步进马达,有一篇很好的英文材料: https://www.hackster.io/erickbp/stepper-motor-and-windows-10-iot-core-d3c5d6 我的例子就是基于上面这 …
Windows IoT Raspberry Pi

Sound Controlled Light by Windows 10 IoT Core

In many buildings, there are sound controlled light in use. When you clap your hands, the light turns on. Now, with Raspberry Pi 3 and Windows 10 IoT, we can make a sound controlled light ourselves. The sound sensor I use is FC-04. As other sensors, the first step is calibration. 1. Calibration for FC-04 Sound Sensor In quiet environment. Connect VCC to DC 3.3V,GND to Ground. At that time, the …
Windows UWP IoT Raspberry Pi

Windows 10 IoT: Detect Range with HC-04 Ultrasonic Sensor on Raspberry Pi 3

HC-04是树莓派上用的比较广泛的超声波传感器,可以用来测量设备和物体之间的距离。可惜网上的资料很少有针对Windows 10的,几乎都是Python和C在Linux上的例子。 hackster.io上有一篇用HC-04做雷达的例子,但是设计的部件太多了,对单纯学习HC-04传感器的使用来说这个例子比较复杂。搜了一圈,英文资料最好的是这篇:http://www.guruumeditation.net/en/digital-io-with-windows-10-iot-raspberry-pi-2-and-the-ultrasonic-ranging-module-hc-sr04/ 国内中文资料介绍Windows 10上HC-04传感器的文章似乎还没有,所以就简单总结一下步骤。 一、物理连接 对于没有多少物理和电子知识基础的人(比如我)来说,第一步连线是比较难的。很多文章都一笔带过说“这很 …
Windows UWP IoT Raspberry Pi

Windows 10 IoT Development: Moisture Sensor for Raspberry Pi 3

I bought a moisture sensor like this recently. After some research, there seem no articles to indicate how to use it in Windows 10. So I figured out myself. This sensor has 4 Pins, which are: PIN Usage AO Analog Out DO  Digital Out GND  Ground  VCC  Power So, let's connect VCC to DC3.3v on RPi, I use PIN 01. Connect GND to any ground header, which I use …
Windows UWP IoT Raspberry Pi

GY-30 (BH1750FVI) Light Sensor with Windows 10 IoT

I purchased a GY-30 light sensor recently, this model is also known as "BH1550FVI". There seems no sample for this sensor on Windows 10 yet, so I tried to make one. The light sensor looks like this: My board is a Raspberry Pi 3, the GPIO layout is shown in this table: Because GY-30 is an I2C device, so we can not use GPIO to drive it directly, we must use the I2C ports. In addition, …
Windows UWP IoT Raspberry Pi

Windows 10 IoT开发:UWP应用调用关机和重启命令

UWP通常是没有让设备关机和重启的权限的。但是在Windows 10 IoT Core中是有办法实现的。安装Windows 10 Iot Core之后默认启动的那个欢迎页面右上角是有关机和重启按钮的。其实就是个UWP,它的源代码在:https://github.com/ms-iot/samples/tree/develop/IoTCoreDefaultApp  分析源代码可以发现,关机和重启是通过ShutDownManager这个class实现的。 #region Assembly Windows.System.SystemManagementContract, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime // C:\Program Files (x86)\ …
Windows UWP IoT

Azure Remote Controlled Light with Windows 10 IoT Core

For those who have watched the "Big Bang Theory", you would probably remember that those physicists build an Internet controlled lamp. The signal send from their laptop traveled around the world and come back to their house to light up the lamp. Now, with Windows 10 IoT Core and Microsoft Azure, we could also achieve the same thing on a Raspberry Pi 3. First, I strongly recommend you to read …
Windows Azure IoT Raspberry Pi

Windows 10 UWP开发:如何不让界面卡死

自从.NET 4.5开始,C#多了一对新的异步关键词 async 和 await,如果不了解的朋友可以简单的看下下面的示意图。 简单的说,就是在通常情况下,用户在界面上进行的操作,比如点击一个按钮之后,如果进行大量的计算,或者读写文件、网络请求等耗时的操作,那么程序的界面就会卡住,在这段时间里,任何交互都不会响应,直到后台的代码执行完毕才会继续响应用户操作。 这种现象和你的应用是不是UWP没有什么卵关系,WinForm,WPF,Windows Phone SL/RT应用都会有这个问题。 这个问题的原因是因为这些耗时的操作和界面(UI线程)没有关系,但却在UI线程上执行了。解决办法就是另起一个线程,让它在UI线程之外去执行代码,这样就不会锁死UI。就像这图: 在.NET 4.5以前,要进行一个异步操作写法有点繁琐,.NET 4.5以后。我们只要把一个方法的签名声明为 …
Windows Async Async Await UWP

Windows 10 UWP开发:页面导航及后退的处理技巧

这篇文章主要总结一下Windows 10 UWP开发中关于页面导航及后退按钮的一些省时省力的技巧。 一、页面导航 导航到另一个页面,用的是Frame的Navigate方法,parameter参数是可选的: public System.Boolean Navigate(Type sourcePageType, System.Object parameter); 比如你的目标页面是TargetPage.xaml,通常类型就是TargetPage,所以就可以这样搞: Frame.Navigate(typeof(TargetPage), ParametersObject); 在目标页面接受参数,用的是OnNavigatedTo,然后把e.Parameter转换成你的参数类型,再自己撸一下就好,比如: protected override void OnNavigatedTo( …
Windows UWP

How to Make Circular Avatar in Windows 10 UWP

Once upon a time, all user's avatar used to be square. Since Apple's design, now a lot of apps and websites would use a circular avatar instead of a squre one. This is how we used to make square avatar: Starting from Windows 10, Microsoft became the biggist Apple fans, so they changed avatars to circular in Windows system. So how can we make one in XAML without acutally cropping the …
Windows UWP

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