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 596653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:11:41+00:00 2026-05-13T16:11:41+00:00

var a1 = HEL; var a2 = HELLO; var a3 = LLO; var length

  • 0

var a1 = “HEL”;
var a2 = “HELLO”;
var a3 = “LLO”;
var length = a2.Length+5;

        listbox.Items.Add(a1.PadRight(length) +"End");
        listbox.Items.Add(a2.PadRight(length) + "End");
        listbox.Items.Add(a3.PadRight(length) + "End");

I have code like this to obviously pad all text so that the word End lines up.

The problem is I have to change the font from the wpf listbox from Segoe UI to Courier New to have this work. The rest of my app uses Segoe UI, so I think it looks weird here.

Is there any way to achieve the result with Segoe UI or maybe a similar font with correct spacing I could use, or maybe someone has some other smart solution i haven’t even thought of? 🙂

Thanks

edit

at the end of the day I want this to display to related items like this:

ITEM A    -> ITEM B
ITEM X    -> ITEM Y
ITEM C    -> ITEM E

dont want to use gridview.

  • 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-13T16:11:41+00:00Added an answer on May 13, 2026 at 4:11 pm

    Feed the ListBox the two pieces of data separately, and use a data template. Here’s how.

    First, create a little class to represent each item you want to insert:

    public class WordPair {
      public string First { get; set; }
      public string Second { get; set; }
    }
    

    (You probably already have a suitable class and/or collection in your application — I assume those pairs of strings are coming from somewhere!)

    Second, set your ListBox.ItemsSource to a collection of these things:

    listBox.ItemsSource = new List<WordPair> {
      new WordPair { First = "ITEM A", Second = "ITEM B" },
      new WordPair { First = "ITEM X", Second = "ITEM Y" },
    };
    

    Again, this collection may already exist in your app.

    Third, create a DataTemplate specifying the desired layout, and assign it to your ListBox.ItemTemplate:

    <!-- in your Window.Resources section -->
    <DataTemplate x:Key="AlignedPairs">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <TextBlock Text="{Binding First}" Grid.Column="0" />
        <TextBlock Text="->" TextAlignment="Center" Grid.Column="1" />
        <TextBlock Text="{Binding Second}" TextAlignment="Right" Grid.Column="2" />
      </Grid>
    </DataTemplate>
    
    <ListBox Name="listBox" ItemTemplate="{StaticResource AlignedPairs}">
      <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
          <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
      </ListBox.ItemContainerStyle>
    </ListBox>
    

    (I’ve guessed at the exact alignment you want for the items, but you can obviously tweak it.)

    Note that you also need to set the HorizontalContentAlignment of the ListBoxItems to Stretch using ListBox.ItemContainerStyle. Otherwise each ListBoxItem will take up only the space it needs, resulting in all the Grid columns being minimal size and looking like a straight concatenation. Stretch makes each ListBoxItem fill the full width so the Grid columns are forced to grow accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.