Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF scrollbar for a resizable window

This should be a very simple task, but for some reason I'm running into a lot of problems with it in WPF.

This is what I want to happen: I have a bunch of controls in a window, including expander controls. I want to have scroll bars for that window, when content expands below the visible area. Also, the window is not of fixed width, it can be maximized, resized, etc.

I tried putting a ScrollViewer as the first element in the window, but it's not working correctly. If I set the height and width to Auto, it doesn't scroll and if i set it to spefic detentions, it creates a box when the window is maximized.

Any help would be greatly appreciated!

like image 228
Greg R Avatar asked Feb 25 '10 20:02

Greg R


People also ask

How do I make a WPF window scrollable?

There are two predefined elements that enable scrolling in WPF applications: ScrollBar and ScrollViewer. The ScrollViewer control encapsulates horizontal and vertical ScrollBar elements and a content container (such as a Panel element) in order to display other visible elements in a scrollable area.

How do I add a ScrollBar in WPF?

How to enable scrollbar in a WPF TextBox. The simplest way to add scrolling functionality to a TextBox control is by enabling its horizontal and vertical scrolling. The HorizontalScrollBarVisibility and VerticalScrollBarVisibility properties are used to set horizontal and vertical scroll bars of a TextBox.

How do I add a ScrollBar to my grid?

In the presentation tab of table layout properties, Choose width of content as Pixels(Fit Content) to see a horizontal scroll bar only for the grid with more columns.


1 Answers

I'm assuming that you have some fixed width issues. If you provide a sample of your XAML I can see if I can help further. The following works without showing a box:

<Window x:Class="WpfSample1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <ScrollViewer>
        <StackPanel>
            <Rectangle Height="400" Width="400" Fill="Red" Margin="10" />
            <Rectangle Height="400" Width="400" Fill="Green" Margin="10" />
            <Rectangle Height="400" Width="400" Fill="Blue" Margin="10" />
            <Rectangle Height="400" Width="400" Fill="Yellow" Margin="10" />
        </StackPanel>
    </ScrollViewer>
</Window>
like image 90
bendewey Avatar answered Nov 16 '22 01:11

bendewey