Live Chat Icon For mobile
Live Chat Icon

How do I make the items in the ListBox be a combination of values from 2 different columns in my data source?

Platform: WPF| Category: ListBox

First create a custom DataTemplate that uses adjacent TextBlocks to render values from 2 different columns next to each other.


<Window.Resources>  
            <DataTemplate x:Key='lbItemsTemplate'>   
                <StackPanel FlowDirection='LeftToRight'  Orientation='Horizontal'>   
                    <TextBlock Text='{Binding Path=Title}'></TextBlock>  
                    <TextBlock Text=' \ '></TextBlock>  
                    <TextBlock Text='{Binding Path=Summary}'></TextBlock>  
                </StackPanel>  
            </DataTemplate>  
</Window.Resources>  

Above, Title and Summary are the two columns.

Then specify this template in your ListBox:


<ListBox x:Name='ListView1' ItemTemplate='{StaticResource lbItemsTemplate}' ItemsSource='{StaticResource InventoryData}'>   
</ListBox>  

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.