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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:21:12+00:00 2026-06-03T06:21:12+00:00

I’m bulding a small WPF app over here. It’s all built strictly with MVVM,

  • 0

I’m bulding a small WPF app over here. It’s all built strictly with MVVM, using nothing but DataTemplates linked to view model types.

I’ve seen alot of questions about how to stretch and clip the contents of ListBoxes so that the items fill its parent. After alot of experimenting I managed to get my head around that but now I find myself in the same scenario with the ItemsControl but the same tricks doesn’t seem to work.

Here’s one of the DataTemplates in use (a simple TextBox). Note how I tried setting the HorizontalAlignment …

<DataTemplate DataType="{x:Type vm:OneOfMyViewModelTypes}">
    <TextBox 
        Text="{Binding Path=Value}"
        HorizontalAlignment="Stretch"
        />
</DataTemplate>

Here’s the ItemsControl inside a Grid …

<Grid Background="Gray">
            <Grid.Margin>
                <Thickness 
                    Left="{StaticResource ConfigurationDefaultMargin}" 
                    Right="{StaticResource ConfigurationDefaultMargin}" 
                    Bottom="{StaticResource ConfigurationDefaultMargin}" 
                    Top="{StaticResource ConfigurationDefaultMargin}" 
                    />
            </Grid.Margin>
            <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="_key" Width="Auto"/>
                <ColumnDefinition SharedSizeGroup="_value" Width="*"/>
            </Grid.ColumnDefinitions>

            <ItemsControl 
                Background="DimGray" 
                Grid.IsSharedSizeScope="True"
                ItemsSource="{Binding Path=Configuration, Mode=OneWay}" 
                HorizontalAlignment="Stretch" 
                HorizontalContentAlignment="Stretch"
                >
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition SharedSizeGroup="_key"/>
                                <ColumnDefinition SharedSizeGroup="_value"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock
                                Style="{StaticResource ExtensionConfigurationLabel}"
                                Grid.Column="0"
                                Margin="5,5,5,0"
                                Text="{Binding Path=Caption}" 
                                />
                            <ContentPresenter 
                                Grid.Column="1"
                                HorizontalAlignment="Stretch"
                                Margin="5,5,5,0"
                                Content="{Binding}" 
                                />
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>

I’ve used colors to see how the controls sizes. The Grid is gray and the ItemsControl is dark gray.

This is the result …

This is the result

As you can see from the colors the containing Grid stretches while the ItemsControl does not. I did set its HorizontalAlignment property to Stretch but it seems it has no effect. Is there anything else I need do?

Thanks

  • 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-03T06:21:14+00:00Added an answer on June 3, 2026 at 6:21 am

    You have two columns in your main (outer) grid, yet you use only the first column.
    The second column uses all the remaining space.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.