Is it possible to bind 2 properties into a single DataGrid field?

binding, c#, wpf, xaml

Solution

One option would be to create a compound template column based on two textblocks which would still allow the form to update when changes to either property are made.

eg.

<DataGridTemplateColumn Header="Customer Name">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=Customer.ForeName}"/>
                <TextBlock Text="{Binding Path=Customer.SurName}"/>
            </StackPanel>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Problem

At the moment I have the following: ``` <DataGridTextColumn Header="Customer Name" x:Name="columnCustomerSurname" Binding="{Binding Path=Customer.FullName}" SortMemberPath="Customer.Surname" IsReadOnly="True"> </DataGridTextColumn> ``` where `Customer.FullName` is defined as: ``` public string FullName { get { return string.Format("{0} {1}", this.Forename, this.Surname); } } ``` The binding works, but not ideally. If someone updates the `Forename` or `Surname` properties the update is not reflected in the DataGrid until it is refreshed. I found issues similar to this, e.g. https://stackoverflow.com/a/5407354/181771 which uses `MultiBinding` but this works with a `TextBlock` rather than with a `DataGrid`. Is there another way for me to get this working?

Original source