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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:37:34+00:00 2026-05-21T05:37:34+00:00

Just trying to get my head round WPF. I have a usercontrol which I’m

  • 0

Just trying to get my head round WPF. I have a usercontrol which I’m using as the template for items in a listbox, however no matter what I try the usercontrol’s width is always shrinking to the minimum size but I want it to fill the available width. I’ve found a similar query on here but it was relating just to a usercontrol not within a listbox and the solution proposed doesn’t apply here.

My UserControl is defined as :

<UserControl x:Class="uReportItem"
         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" 
         d:DesignHeight="60" d:DesignWidth="300">
<Grid >
    <Border CornerRadius="3,3,3,3" BorderBrush="#0074BA" BorderThickness="1" Background="#00D6F9" Margin="0">
        <DockPanel Margin="3,3,3,3">
            <Grid Height="Auto">
                <!-- Grid Definition-->
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <!-- Content -->

                <!-- Top Row-->
                <Button Grid.RowSpan="2">Delete</Button>
                <StackPanel Orientation="Horizontal" Grid.Column="1">
                    <Label x:Name="Heading" Content="{Binding Heading}" FontSize="14" FontWeight="bold"></Label>
                    <Label x:Name="Subheading" Content="{Binding SubHeading}" FontSize="14"></Label>
                </StackPanel>
                <Button Grid.Column="2">Blah</Button>


                <!-- Second Row-->
                <Label Grid.Row="1" Grid.Column="1" x:Name="Comments">Comments</Label>
                <Button Grid.Column="2">Blah</Button>
            </Grid>
        </DockPanel>
    </Border>
</Grid>

And the implementation on the window is :

<Window x:Class="vReport"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RecorderUI"
Title="vReport" Height="300" Width="300" Background="#00BCF0">

<Window.Resources>
    <DataTemplate x:Key="Record" DataType="ListItem">
        <Grid>
            <local:uReportItem></local:uReportItem>
        </Grid>
    </DataTemplate>
    <Style TargetType="ListBoxItem">
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
    </Style>
</Window.Resources>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>

    <local:uReport Margin="5" Grid.Row="0"></local:uReport>

    <Border Grid.Row="1" BorderBrush="#0074BA" CornerRadius="3">
        <ListBox Margin="5" Background="#00D6F9" BorderBrush="#0074BA" x:Name="ListRecords" ItemsSource="{Binding Items}" ItemTemplate ="{StaticResource Record}"></ListBox>
    </Border>

    <TextBlock Grid.Row="2" x:Name="SelectedItem" Text="{Binding Path=SelectedItem.Heading, Mode=TwoWay}"></TextBlock>
</Grid>

Any ideas?

  • 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-21T05:37:35+00:00Added an answer on May 21, 2026 at 5:37 am

    Try setting HorizontalContentAlignment to Stretch on the ListBox:

    <ListBox Margin="5" Background="#00D6F9" BorderBrush="#0074BA" x:Name="ListRecords" ItemsSource="{Binding Items}" ItemTemplate ="{StaticResource Record}" HorizontalContentAlignment="Stretch"></ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just trying to get my head round Spring and figuring out how I wire
Just trying to get my head round the responsibilities of the service layer and
Just trying to get my head around Generics by reading this enlightening article by
just exploring c# 4. Trying to get my head around all this dynamic stuff.
I've just started foraying into EF, and I'm trying to get my head around
Hey, I'm just trying to get things 100% clear in my head in regards
Just trying to get my irb sessions to actually list the current line of
Just trying to get up to speed with the SDK... So, I've created my
I'm just trying to get a general idea of what views are used for
I'm just trying to get MySQL to store time in GMT... I've read the

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.