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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:41:30+00:00 2026-05-27T23:41:30+00:00

I want to right-align the contents that are displayed in a vertically oriented StackPanel

  • 0

I want to right-align the contents that are displayed in a vertically oriented StackPanel, I’ve tried HorizontalAlignment="Right" on the StackPanel itself and the control in the ListBox's DataTemplete (in this case a TextBox, but in reality I have a UserControl in the real app)

here is the current result… i want the right edge of each TextBox to be right-aligned…

not right-aligned

Here is the xaml, pretty simple…

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:WpfApplication2="clr-namespace:WpfApplication2"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance WpfApplication2:Model, IsDesignTimeCreatable=True}">
    <ListBox ItemsSource="{Binding Numbers}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBox Text="{Binding Mode=OneWay}" BorderBrush="Black" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Window>

and here is the model I’m using to test this out with…

using System;
using System.Collections.Generic;
using System.Linq;

namespace WpfApplication2
{
    public class Model
    {
        [ThreadStatic]
        static IDictionary<int, string> dict;

        public string[] Numbers
        {
            get { return dict.OrderBy(x => x.Key).Select(x => x.Value).ToArray(); }
        }

        public Model()
        {
            if (dict != null) return;
            dict = new Dictionary<int, string>
                       {
                           {1, "one"}, 
                           {2, "two"},
                           {3, "three"},
                           {4, "four"},
                           {5, "five"},
                           {6, "six"},
                           {7, "seven"},
                           {8, "eight"},
                           {9, "nine"},
                           {10, "ten"},
                           {11, "eleven"},
                           {12, "twelve"},
                           {13, "thirteen"},
                           {14, "fourteen"},
                           {15, "fifteen"},
                           {16, "sixteen"},
                           {17, "seventeen"},
                           {18, "eighteen"},
                           {19, "nineteen"},
                           {20, "twenty"},
                           {30, "thirty"},
                           {40, "forty"},
                           {50, "fifty"},
                           {60, "sixty"},
                           {70, "seventy"},
                           {80, "eighty"},
                           {90, "ninety"},
                           {100, "one hundred"},
                           {200, "two hundred"},
                           {300, "three hundred"},
                           {400, "four hundred"},
                           {500, "five hundred"},
                           {600, "six hundred"},
                           {700, "seven hundred"},
                           {800, "eight hundred"},
                           {900, "nine hundred"},
                           {1000, "one thousand"},
                       };

            for (var number = 1; number <= 1000; number++)
            {
                if (dict.ContainsKey(number)) continue;

                var divisor = number < 100 ? 10 : 100;
                var separator = divisor == 100 ? " and " : "-";

                var key = (number / divisor) * divisor;
                var mod = number % divisor;
                dict.Add(number, dict[key] + separator + dict[mod]);
            }
        }
    }
}
  • 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-27T23:41:31+00:00Added an answer on May 27, 2026 at 11:41 pm

    Use the ListBox.ItemContainerStyle to set the HorizontalContentAlignment of the ListBoxItems to Right.

    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="HorizontalContentAlignment" Value="Right"/>
        </Style>
    </ListBox.ItemContainerStyle>
    

    Note: This is different from setting the HorizontalAlignment in that the items will still span the whole ListBox which has an impact on item selection.

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

Sidebar

Related Questions

I have a couple of <p> tags that I want to right align. Does
I want to right-align an inline element to the right of a div .
I have a periodically_call_remote that I want to fire right away (as if the
I want to use asp.net repeater control to display all threads that under same
I'm generating titles out of a few other fields, and want the right way
I want to apply right alignment on the last cell of every table row,
I want to create a right click context menu for my textboxes to provide
I want to make a right click menu for my winforms app. It will
I want my controller to return the right HTTP response code when the user
Right up front: I do not want to start a religious war. I've used

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.