UWP
Tags: csharp, dotnet
Published: 2020-08-15 22:14:28

I've had a lot of experience developing WPF (Windows Presentation Foundation) applications, but this week I decided to learn more about UWP (Universal Windows Platform). I was able to find a free, RESTful API which hosts COVID-19 data at covid19-api.org, and decided to build a statistical application based on the data provided. While I can't confirm the accuracy of the data, the API is extremely easy to use, and it was a perfect foundation to build an application substantial enough for me to dive deeper into UWP.

WPF is one of my favorite subsystems for building Windows applications. There's plenty of well-written documentation, and a large community of professionals who consistently provide free resources to learn everything there is to know about the platform. UWP, however, is one of the worst when it comes to documentation, and there's a severe lack of resources available. I'm not entirely surprised by this, as the platform is intended to provide a means of developing applications, which are capable of running on all of Microsoft's operating systems. In other words, there's a specific reason to develop for the UWP platform, which isn't commonly sought after.

One of the first issues I encountered, was the inability to bind the properties of an element (in my case, a canvas) to a relative view-model. Two-way binding is available to use in UWP, however, the option to bind one way to source does not exist. What I was attempting to achieve involved graphing lines on a canvas to represent the growth of cases, deaths, and recoveries over the past thirty days. The problem is, I wanted the data representation to scale proportionately to the height and width of the canvas. This would involve tracking the height and width of the canvas from an object within the view-model. Without the option to bind the height and width one way to source, I would either have to represent the data context and canvas of the view in code behind, and respond to an event every time the size of the canvas changed in order to scale the data, or scrap the idea of a dynamic graph all together. There are both free, and paid, third-party options for implementing charts and graphs into a UWP application, although, I was adamant to develop a solution myself. In my attempt to develop a solution, I was introduced to my second issue.

While I have leveraged data grids in WPF applications to represent observable collections, I now needed to learn how to display a collection using a custom control. After reading through tons of poor documentation and dozens of hopeless Stack Overflow posts, I realized that I needed an items control to resolve the issue. An items control in WPF and UWP behaves similarly to a container in React.js, where you use a collection of objects as a context for the instantiability of UI elements. Being new to this control, I struggled to override the default styling, and my data was being cascaded down, as if each rendered line existed within a stack panel. In retrospect, I believe using a grid as the items control's template may have resolved this, but I clearly need to practice employing these structures more to gain an understanding of how they operate. In the end, I was able to get the graph working, although, it was a fixed size, looked somewhat hideous, and I resorted to using thirty line elements to render the data in lieu of the items control, so I opted to represent the data through percentages.

I'm glad I decided to take on this challenge, as I learned many new techniques that I will be able to apply to my WPF applications and developed a much greater understanding of the UWP platform. I plan to continue on improving this application, and learn much more along the way. For anyone interested in learning how to develop .NET applications, I would strongly suggest avoiding the UWP platform until you are familiar with WPF.