Say I have a class like this:
public class MyClass
{
public string Name;
public int Id;
public override string ToString()
{
return this.Id.ToString() + " - " + this.Name;
}
}
If I bind a datagrid text column to an object instance of this class (without using a converter), the overridden ToString is called and displays the Id - Name successfuly. However, when I bind the same object to a TextBlock's Text property, the ToString is never called and Text is empty. I know I could use a converter, but I'm trying to understand why the binding doesn't call the ToString like it does when I bind to the datagrid column.
Datagrid column binding (datagrid's item source is a collection of MyClass objects):
<DataGridTextColumn Binding="{Binding .}" Header="Id - Name"/>
TextBlock binding:
<TextBlock><Run Text="{Binding myClass, ElementName=UserControl}"/></TextBlock>
Note: if I change myClass to myClass.Name, then it successfully displays the Name property.