0

So I have my List view in XAML:

<ListView Name="lstContacts">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}"/>
            <GridViewColumn Header="Name" DisplayMemberBinding="{Binding FullName}"/>
        </GridView>
    </ListView.View>
</ListView>

Then I have contacts Table pulled from the Database Using LINQ and converted to a List. Then I bound the list ItemsSource to the table like this.

MyDatabaseDataContext dc = new MyDatabaseDataContext();
lstContacts.ItemsSource = dc.Contacts.ToList();

And all works fine as far as I can bind to a specific column like "ID" or the "FirstName" "LastName" of my table. But I want to combine the "FirstName" and "LastName" to bind to one column as "FullName". I am sure this is something simple and several ways to do it. But for the life of me I can't figure it out. Any help would be much apreciated

MD XF
  • 7,860
  • 7
  • 40
  • 71
  • You didn't bind anything, by the way. There's no instance of `Binding` there. You're just assigning something to a property. Anyhow, what you want is a template column: http://stackoverflow.com/a/4725474/424129 -- just put a TextBlock in the template with two TextBlocks inside it (you can do that) with firstname bound to one and lastname bound to the other. – 15ee8f99-57ff-4f92-890c-b56153 Oct 19 '16 at 02:28
  • @EdPlunkett Oh... sorry I am very new to all of this and have been teachign my self from youtube and here etc. But thanks for your help! – Boyd Barlow Oct 19 '16 at 17:41

1 Answers1

1

You can use MultiBinding:

 <GridViewColumn Header="Name" Width="120" >
      <GridViewColumn.CellTemplate>
           <DataTemplate>
                <TextBlock TextWrapping="Wrap" Width="385">
                      <TextBlock.Text>
                            <MultiBinding StringFormat="{}{0} {1}">
                                  <Binding Path="FirstName" />
                                  <Binding Path="LastName" />
                            </MultiBinding>
                      </TextBlock.Text>
                </TextBlock>
          </DataTemplate>
     </GridViewColumn.CellTemplate>
  </GridViewColumn>
Cycloguy
  • 221
  • 3
  • 6