binding to the ToString() method in a DataTemplate

user1151923 picture user1151923 · Nov 29, 2012 · Viewed 15.3k times · Source

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>

Answer

amnezjak picture amnezjak · Nov 29, 2012

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