How to use string resource in TextBox

Apptacular Apps 386 Reputation points
2020-06-04T13:55:52.487+00:00

How can a string resource be used for a TextBox?

I understand that I need to use something like:

<x:String x:Key="Placeholder">Placeholder Content</x:String>

but I don't know how.

<TextBox 
    x:Name="nameInput"
    PlaceholderText="Find a setting"
    Width="300" 
    HorizontalAlignment="Left"
    Margin="0,0,0,20" />
Universal Windows Platform (UWP)
{count} votes

2 answers

Sort by: Most helpful
  1. Daniele 1,996 Reputation points
    2020-06-04T14:05:16.147+00:00

    If I understand correctly you want to put that Placeholder in TextBox.PlaceholderText. Then define a resource

    <Page.Resources>
        <x:String x:Key="Placeholder">Placeholder Content</x:String>
    </Page.Resources>
    

    and use it as StaticResource in the TextBox.PlaceholderText

    <TextBox PlaceholderText="{StaticResource Placeholder}"/>
    
    0 comments No comments

  2. Matt Lacey 791 Reputation points MVP
    2020-06-04T14:32:09.097+00:00

    You can also define strings in a resource (RESW) file and use Unique Identifiers (Uid) to connect the resource with where it should be used:

    9161-placeholdertext-resource.png

    0 comments No comments