Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6169983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:57:11+00:00 2026-05-23T22:57:11+00:00

I have a listBox and add data to it like so: for (int x

  • 0

I have a listBox and add data to it like so:

for (int x = 0; x < Orchestrator.Instance.getTopicCount(); x++)
{
   listTopics.Items.Add(Orchestrator.Instance.getTopic(x));
}

But I need to be able to do things like have text wrapping and divider lines, so I would like to do it the XAML.

Microsoft shows this:

<TextBlock Width="248" Height="24" 
Text="{Binding ElementName=lbColor, Path=SelectedItem.Content, 
Mode=OneWay}" 
x:Name="tbSelectedColor" 
Background="{Binding ElementName=lbColor, Path=SelectedItem.Content, 
Mode=OneWay}"/>

But I don’t really understand it. Here is my XAML:

<ListBox Height="261" HorizontalAlignment="Left" Margin="352,38,0,0" Name="listContent"     VerticalAlignment="Top" Width="391" Grid.Column="1" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" MaxWidth="391" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>

How am I able to achieve what I want? (Divider lines, text wrapping so I don’t have to scroll horizontally, and data binding)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:57:13+00:00Added an answer on May 23, 2026 at 10:57 pm

    To specify the layout of each item, there are two different things you can change: the ItemContainerStyle, which provides the ControlTemplate used for each ListBoxItem, or the ItemTemplate, which provides the DataTemplate that is used to render each data item. The ItemTemplate is simpler to use if you’re just getting started and haven’t gotten the hang of ControlTemplates yet.

    To get your text to wrap, there are two key things to do. Turn off the default horizontal scrolling of ListBox (which you got already), and set the TextWrapping property of your TextBlock to Wrap. To get to the TextBlock you need to define it in your ItemTemplate. Here’s a simple example of the template declared inline, though you could also pull it out as a Resource. For the dividing line I used the simplest approach of a Border with only a bottom black line.

    <ListBox x:Name="listContent" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Border BorderThickness="0,0,0,1" BorderBrush="Black">
                    <TextBlock Text="{Binding}" TextWrapping="Wrap"/>
                </Border>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .net winforms ListBox and I've added items to it using .Add().
Hi all i have a listbox MainListBox where i add items to dynamically. Now
I have two ListBoxes, lstAvailableColors and lstSelectedColors. Between each listbox are two buttons, Add
I have a listbox where the items contain checkboxes: <ListBox Style={StaticResource CheckBoxListStyle} Name=EditListBox> <ListBox.ItemTemplate>
I have a ListBox which displays items of variable height. I want to show
I have a listbox (listBox) and a dropdown list(dropDown). I want to be able
I have a sorted listbox and need to display each item's row number. In
It is MVVM project. I have a ListBox with TabControls inside of it's items.
I'm not using a listbox and data binding at the moment, but is it
I have a add to list button.when user clicks on button the data in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.