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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:32:13+00:00 2026-06-09T15:32:13+00:00

The code below is the complete representation of the problem. Essentially, when I have

  • 0

The code below is the complete representation of the problem. Essentially, when I have a ListBox inside a ScrollViewer the ListBox won’t show its own scrollbar. Rather, it relies on the scrollbar of the parent ScrollViewer. In my situation I have my entire control wrapped in a ScrollViewer so that I get scrollbars when the MinHeight/MinWidth are violated. The ListBox is just one of numerous controls in my UserControl and I don’t want my UserControl jumping to wide proportions to match the items in the ListBox. What would you add to the code below to force the ListBox to use its own scrollbar?

using System;
using System.Windows;
using System.Windows.Controls;

namespace TestExpanderWidth
{
    class Program
    {
        [STAThread]
        static void Main()
        {
            var listbox = new ListBox { Margin = new Thickness(10.0), MinWidth = 400 };
            listbox.Items.Add(new string('c', 3000));

            var sv = new ScrollViewer {HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, VerticalScrollBarVisibility = ScrollBarVisibility.Auto};
            sv.Content = listbox; // remove for test

            var window = new Window { Width = 600, Height = 400 };
            window.Content = sv; // remove for test
            //window.Content = listbox; // add for test

            var application = new Application();
            application.Run(window);
        }
    }
}
  • 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-09T15:32:15+00:00Added an answer on June 9, 2026 at 3:32 pm

    I’m not sure if this is the best way to do this, but for all intense and purposes it seems to provide the functionality that you requested.

    public MainWindow()
        {
    
            InitializeComponent();
    
        }
    
        public void WindowLoaded(object sender, EventArgs e) 
        {
            listbox = new ListBox { Margin = new Thickness(10.0), MinWidth = 400, MinHeight = 400 };
            listbox.Items.Add(new string('c', 3000));
    
            var sv = new ScrollViewer { HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, VerticalScrollBarVisibility = ScrollBarVisibility.Auto };
            sv.Content = listbox; // remove for test
    
            this.Width = 600;
            this.Height = 400;
            this.Content = sv;
    
        }
    
        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
    
            base.OnRenderSizeChanged(sizeInfo);
            if (listbox != null)
                listbox.MaxWidth = this.RenderSize.Width - (int.Parse(listbox.Margin.Right.ToString()) * 4);
    
        }
    

    Basically, I’ve assigned the ListBox a MaxWidth which is based on the Window’s Render Width, and to trigger the event I’ve overridden the OnRenderSizeChanged event handler.

    Hope this helps you and works how you want!

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

Sidebar

Related Questions

The code below makes complete sense to me - its about adding an element
My app is almost complete. In the second snippet of code below, you will
Below is the complete code of the jquery AJAX tab script I am working
The complete code is copied and pasted below. I am new to javascript and
Code below is working well as long as I have class ClassSameAssembly in same
I have the code below. I want to send the value of value1 n.value1s
whenever i run the code below it occurs to me I have made a
I need your opinion about this code below. I have a list of messages:
I have the code below (but doesn't work) .. i need to wait till
I have the code below which works fine, steps through the rows pinging each

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.