Search code examples
wpfxamltypeconvertertemplatebinding

How to use Tag as String with TemplateBinding in WPF?


So I have this Hint TextBox that I'm making, the template for which is shown below..

<ControlTemplate Type="TextBox">
  <Border>
    <Grid>
      <TextBlock Text="{TemplateBinding Tag}"/>
      <ScrollViewer x:Name="PART_ContentHost"/>
    </Grid>
  </Border>
</ControlTemplate>

I wanted to use the 'Tag' property of the Textbox as the 'hint text' since a 'hint' property isn't readily available. But the Tag being an 'object' type wasn't among the suggested options.

How can I go about fixing this?

Additional Information:

  • I've looked into converters and they seem to require a c# code to do the dirty job. Is a solution possible where the casting takes place in XAML only?
  • Visual Studio 2017

Solution

  • Turned out that Visual Studio (2017) just didn't show 'Tag' as a suggestion. But it worked when I typed it in anyway. WPF recognised the tag as string. Conversion wasn't necessary. The {TemplateBinding Tag} code in the Question is correct, and it works.