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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:06:45+00:00 2026-05-11T00:06:45+00:00

I have a problem. I need to host grid with controls in ScrollViewer to

  • 0

I have a problem. I need to host grid with controls in ScrollViewer to prevent textbox from being either truncated or collapsed to zero-with at the UI. Also I want the with of textbox to be expanded when user change windows width. I’m setting Window’s content to following code

<DockPanel>     <TreeView DockPanel.Dock='Left' Width='150'/>     <ScrollViewer VerticalScrollBarVisibility='Auto' HorizontalScrollBarVisibility='Auto'>         <Grid>             <Grid.ColumnDefinitions>                 <ColumnDefinition Width='Auto'/>                 <ColumnDefinition />             </Grid.ColumnDefinitions>             <Grid.RowDefinitions>                 <RowDefinition Height='Auto'/>             </Grid.RowDefinitions>             <TextBlock Text='Name'                         Margin='5'                         VerticalAlignment='Center'/>             <TextBox Grid.Column='1'                      Text='Some Name'                      Margin='5'                      VerticalAlignment='Center'                      MinWidth='200'/>         </Grid>     </ScrollViewer> </DockPanel> 

All work fine, but when user types very long text in TextBox it is being expanded and horizontal scroll appears. Is there any easy way to limit TextBox maximum width and allow it to be expanded only when user changes window size.

  • 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. 2026-05-11T00:06:45+00:00Added an answer on May 11, 2026 at 12:06 am

    The problem is that the parent elements are providing TextBox with as much space as it thinks it needs, and when more text is present it will expand instead of staying at the initial automatic size.

    One solution here is to make another auto-sized element and bind the TextBox.Width to it:

    <DockPanel>     <TreeView Width='150' DockPanel.Dock='Left'/>     <ScrollViewer HorizontalScrollBarVisibility='Auto' VerticalScrollBarVisibility='Auto'>         <Grid>             <Grid.ColumnDefinitions>                 <ColumnDefinition Width='Auto'/>                 <ColumnDefinition/>             </Grid.ColumnDefinitions>             <Grid.RowDefinitions>                 <RowDefinition Height='Auto'/>             </Grid.RowDefinitions>             <TextBlock Margin='5' VerticalAlignment='Center' Text='Name'/>             <Border x:Name='b' Grid.Column='1' Margin='5'/>             <TextBox Width='{Binding ActualWidth, ElementName=b}'                      MinWidth='200'                      Grid.Column='1'                      Margin='5'                      VerticalAlignment='Center'                      Text='Some Name'/>         </Grid>     </ScrollViewer> </DockPanel> 

    Note that we set the Margin property of the auto-sizing element (the Border). This is important because if it’s not set, there will be a loop:

    1. Border width autosizes to Grid column width
    2. TextBox width resizes to Border.ActualWidth
    3. Grid column width resizes to TextBox width + TextBox margin
    4. Border width autosizes to Grid column width again

    By setting the Margin to the same as the TextBox, the resizing of the TextBox won’t affect the Grid size.

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

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Just declare a property [Serializable] public class MethodLoggingAttribute : OnMethodBoundaryAspect… May 11, 2026 at 2:43 pm
  • added an answer Is it possible for you to use a backup and… May 11, 2026 at 2:43 pm
  • added an answer You'll have to add your company repository under the 'repositories'… May 11, 2026 at 2:43 pm

Related Questions

In our application, we allow administrators of an install to design templates for name
I have a web application that makes heavy use of the Session state to
I'm coding an italian website where I need to validate some input data with
Consider the following setup: A windows PC with a LAN interface and a WiFi

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.