Search code examples
c#wpfxamldatatemplate

binding to the ToString() method in a DataTemplate


Is there any easy way to bind to the ToString() method in a DataTemplate? I would expect the Text property of a TextBlock to use ToString() by default for its Text property, but that does not happen. So any easy way to do this:

<DataTemplate x:Key="myTemplate">
    <TextBlock Text="{Binding ToString()}"/>
<DataTemplate>

Solution

  • You can use Text="{Binding}". The ToString() method is invoked implicitly.