Reputation: 1287
I've developed an UWP app and I would like to add the version number in the app title.
So I used ApplicationView.GetForCurrentView through this code:
var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
string appVersion = string.Format("{0}.{1}.{2}",
Package.Current.Id.Version.Major,
Package.Current.Id.Version.Minor,
Package.Current.Id.Version.Build);
appView.Title = Package.Current.DisplayName + " - v" + appVersion;
I've used this code in App.xaml.cs, in the OnLaunched() method.
But it doesn't work as expected: the default name of the app is always added after the name that I've initialized.
=> Is there any explanation?
Upvotes: 0
Views: 1692
Reputation: 12465
From the docs:
Remarks
The Title property provides a title for the window.
When the Title property is not set, the system shows the app's display name in the title bar, as specified in the Display name field in the app manifest (Package.appxmanifest). When you set the Title property, Windows may choose to append the app display name to the end of the Title value you set.
We recommend that you set a title that describes the window, not the app. If you have an app that can have multiple documents open, each window should have the document title, which is considered more informative than just showing the app name.
For example, assume you have an app named, "My Notes App", with a window showing a document named "Note 1". You should set the Title property to "Note 1". Windows appends the app display name so the title bar shows "Note 1 - My Notes App".
This property is a nonstatic member of the window object. For JavaScript, this means that it is a method of the window object that getForCurrentView creates, and not a method of the ApplicationView class.
Upvotes: 2