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

  • SEARCH
  • Home
  • 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 8793137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:05:06+00:00 2026-06-13T23:05:06+00:00

I have a normal listbox with a custom template to show the items. What

  • 0

I have a normal listbox with a custom template to show the items. What I cannot manage is to stretch the template horizontally over the full widtg of the list box.

My problem is, that all of the elements in the main window are put dynamically, and they resize along with the window size changed method. I’ve searched through the net and the idea was to put HorizontalAligment=”Stretch”. This I tried, everywhere possible, with no significant success.

my xaml code goes like this:

<UserControl x:Class="LiveGames.Dealer.UsersList"
         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" 
         mc:Ignorable="d" 
         Background="Transparent">
<Border CornerRadius="10" BorderBrush="White" BorderThickness="2" >
     <Grid>
        <Grid.Resources>
            <DataTemplate x:Key="PlayerTemplate">
                <WrapPanel>
                    <Border CornerRadius="10" BorderBrush="White" BorderThickness="2" >
                        <Border.Background>
                            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                <GradientStop Offset="0.0" x:Name="gradientOne_Name" Color="Red" />
                                <GradientStop Offset="1.0" x:Name="gradientTwo_Name" Color="DarkRed" />
                            </LinearGradientBrush>
                        </Border.Background>
                        <Grid >
                            <Grid.ColumnDefinitions x:Uid="5">
                                <ColumnDefinition  Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Name="RowH" Height="50"/>
                            </Grid.RowDefinitions>

                            <!--  <TextBlock VerticalAlignment="Center" Margin="5" Grid.Column="0" Grid.Row="1" Text="Player: " FontSize="18" />-->
                            <TextBlock VerticalAlignment="Center" Margin="5" Grid.Column="0" Text="{Binding Path=ID}" FontSize="22" FontWeight="Bold"/>
                        </Grid>
                    </Border>
                </WrapPanel>
            </DataTemplate>
        </Grid.Resources>
        <Canvas>
            <ListBox Name="userList" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" ItemsSource="{Binding}"  ItemTemplate="{StaticResource PlayerTemplate}" HorizontalContentAlignment="Stretch">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem" >
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
        </Canvas>
    </Grid>
</Border>

Does anybody have any idea how to do this, maybe even in the code behind?

M

  • 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-06-13T23:05:07+00:00Added an answer on June 13, 2026 at 11:05 pm

    You can try this:

    <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="Width" Value="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ScrollContentPresenter}}}"></Setter>
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a styled listbox. Listbox items change color when hovered over and when
In WPF, MVVC applicaiton I have quite normal listbox: <ListBox ItemsSource={Binding Friends}> </ListBox> Then
I have a template for my list box item. It includes an image button.
I am trying to build a ListBox with items that have edit states. I
Got a weird problem here. I have created a template for a ListBox based
I have two controls on my form: a listbox with a list of workers
I have normal sqlite database and want to use fts3. As mentioned in http://www.sqlite.org/fts3.html
I have a normal NavigationController. When i open one modalView (using segues) and dismiss
I have a normal textbox in my application. I can paste data to it
I have a normal asp.net page containing some code that I want to measure

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.