Josh Brunton
Josh Brunton

Reputation: 527

Is it possible to ensure that resources can be resolved at compile-time in UWP?

I'm implementing string localisation in a WinUI3 app as documented here on MS Learn (wayback machine).

I noticed that giving an element an invalid x:Uid causes the lookup to quietly fail, and as such, text (or other properties) might not be displayed if the resource can't be found.

Is there a way to ensure at compile-time that all resources referenced in XAML are valid (similar to how x:Bind works in comparison to Binding)?

Upvotes: 1

Views: 80

Answers (1)

Junjie Zhu - MSFT
Junjie Zhu - MSFT

Reputation: 3024

Is there a way to ensure at compile-time that all resources referenced in XAML are valid

To ensure all resources referenced in XAML are valid, it is recommended to use ResourceLoader in code-behind.

Refer to a string resource identifier from code.

var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
this.myXAMLTextBlockElement.Text = resourceLoader.GetString("Farewell");

Upvotes: 0

Related Questions