Creating UWP project
Universal Windows Platform (UWP) is a computing platform created by Microsoft and introduced in Windows 10. UWP is one of many ways to create client applications for Windows, which run on Windows 10 and Windows 11 devices. Application will run on any Windows device no matter whether you are targeting a desktop PC, Xbox, Mixed-reality headset, and so on.
App packages are configured to run on a specific processor architecture. By selecting an architecture, you are specifying which device(s) you want your app to run on. UWP apps can be configured to run on the following architectures:
- x86
- x64
- ARM
- ARM64
It is highly recommended that you build your app package to target all architectures. By deselecting a device architecture, you are limiting the number of devices your app can run on, which in turn will limit the amount of people who can use your app!
LightningChart for UWP
Using LightningChart in UWP works similarly to bindable WPF chart as it has similar binding and MVVM capabilities. As with bindable WPF chart, the collection properties of UWP charts (such as ViewXY axes, 3D lights) are empty by default. Windows 10 and Visual Studio 2017 onwards are required to develop UWP applications with LightningChart. Universal Windows Platform development workload should also be installed on Visual Studio, including the following:
- Microsoft.NETCore.UniversalWindowsPlatform: 6.2.8 or later (Nuget package).
- Microsoft.Toolkit.Uwp: v 4.0.0 or later, 6.0.0 or later recommended. Note that the latest toolkits may not be compatible with earlier target versions.
There are dozens of ready-made UWP projects, which can be extracted from Demo as standalone examples/projects.
Creating a UWP application
Follow these steps to create a UWP application utilizing LightningChart:
- Create a new project with Visual Studio. Select Blank App (Universal Windows).
- Give the project a name and file location.
- Set Target and Minimum versions for the project. Available versions depend on what SDKs have been installed on the machine. For further information see Microsoft’s documentation. Version 16299 or above is recommended. Note that these can be changed later via Project -> Properties.
Selecting Target and Minimum versions for UWP
- When using Target version 2004 or newer, TypeInfoReflection setting should be disabled. Open the *.csproj project file for instance in a text editor and add the following line to each PropertyGroup defining a build condition (Debug|x86, Release|x86 etc.):
<EnableTypeInfoReflection>false</EnableTypeInfoReflection>
- Add LightningChart and SharpDX assemblies to references. By default, these can be found in C:\Program Files\LightningChart\LightningChart .NET SDK v.12\LibUWP. Note that the same UWP assemblies work for x86, x64, Arm and Arm64 platforms. The target platform can be changed by right-clicking the project and selecting Properties -> Build -> Platform target.
References of a UWP project. The LightningChart and SharpDX files are added from the LightningChart installation folder.
- Install Microsoft.Toolkit.Uwp NuGet package to your project. Version 6.0 or newer recommended.
- UWP requires developer key to be set in the application. Extract the key from LicenseManager via “Copy UWP developer key to clipboard” button, then set it in App.Xaml.cs file by using LightningChart.SetUwpDeveloperKey() method.
Using License Manager to copy UWP developer key to clipboard.
Setting the UWP developer key in App.Xaml.cs file.
- It is now possible to create LightningChart components in code or in xaml editor. For example, creating a UWP chart in code:
using LightningChartLib.UWP.ChartingMVVM;
namespace ExampleProject
{
public sealed partial class MainPage : Page
{
private LightningChart _chart = null;
public MainPage()
{
InitializeComponent();
CreateChart();
}
private void CreateChart()
{
_chart = new LightningChart();
// Chart control into the parent container.
(Content as Grid).Children.Add(_chart);
// Disable rendering until the whole chart is set up correctly.
_chart.BeginUpdate();
// Configure chart here.
// Allow rendering the chart.
_chart.EndUpdate();
}
}
}
-
Build, deploy and run the application. In case of app not running (for instance due to “Activation of the Windows Store app…” error), often changing Target and Minimum versions helps.
-
When deploying a UWP application to other machines, deployment key should be applied (see Deployment). Deployment key cannot be used together with development key. Therefore, remove setting the developer key before deploying.
UWP troubleshooting
UWP projects have some known issues. These are often not related to LightningChart but to UWP in general. Therefore, searching for additional information from web is recommended. In any case, don’t hesitate to contact support ([email protected]) if you have any questions.
Some known UWP issues:-
Version 1903 not working. Might give error such as Build error MSB4166: Child node "2" exited prematurely.
This is a known issue specific to 1903. The best fix is to simply use different target version. Microsoft recommends targeting version 2004 (build 19041) or above instead.
-
Release build not working.
Try disabling Compile with .NET Native tool chain via project’s Properties -> Build
-
Debug build not working
In some UWP versions, for instance version 2004, debug build might not run giving error: Run Error: an unhandled win32 exception occurred in [3088] (number is different for different build). In these cases, make sure you have added
<EnableTypeInfoReflection>false</EnableTypeInfoReflection>line to your csproj file. Alternatively, try using release build instead.
-
Activation of Windows Store App ’App name’ failed.
Try cleaning the solution. Delete bin and obj folders and rebuild as instructed here