In Universal Windows Platform (UWP) app development, it's common to display the application's version to users for various reasons, such as tracking updates or providing support. In this article, we will explore how to retrieve a project's version using C# and then display it in a label on the XAML side of the UWP app.
To follow along with this tutorial, you'll need the following:
MainPage.xaml.cs file.using Windows.ApplicationModel;
public string GetAppVersion()
{
PackageVersion version = Package.Current.Id.Version;
return $"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
}
MainPage.xaml file.<Grid>
<!-- Your other XAML elements go here -->
<TextBlock x:Name="versionLabel"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
Foreground="Black"
Text="Version: " />
</Grid>
MainPage.xaml.cs file.