Frank Sposaro
Frank Sposaro

Reputation: 8531

Load string resource for textblock x:Uid in code behind

I have a string resource that I'm using to set as the x:uid for a textblock

<data name="Expected.Text" xml:space="preserve">
    <value>Expected Text</value>
</data>

<TextBlock x:Name="control" x:uid="Expected />

I'm trying to write a Unit test to check if the text is correct. However I can't get a handle on the "Expected" string because it has a .text at the end so that it can be displayed in the TextBlock

ResourceLoader loader = ResourceLoader.GetForCurrentView();
var expected = loader.GetString("Expected");
Assert.AreEqual(expected, control.Text);

This code fails because var expected is blank

Upvotes: 5

Views: 1681

Answers (1)

Fred
Fred

Reputation: 3362

You can access that property via the following notation:

var expected = loader.GetString("Expected/Text");

Source: https://learn.microsoft.com/en-us/windows/uwp/app-resources/localize-strings-ui-manifest#refer-to-a-string-resource-identifier-from-code

Upvotes: 9

Related Questions