How to change scrolling behaviour when resizing window in WPF/XAML - wpf

Research
Currently when working with WPF/XAML, the default scrolling behaviour for the scroll bar is that the VerticalScrollBarVisibility = Visible and the HorizontalScrollBarVisibility = Auto. This means the vertical scroll bar is always visible while the horizontal scroll bar is only visible is the content extends outside the width of the allocated area. Note that while the scrollbar is Visible, if the content do not extend beyong their allocated space, the scroll is deactivated and do not take any user input.
You may change this by changing the values to Visible, Auto, Hidden, or Disabled:
<ScrollViewer VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility = "Auto">
...
</ScrollViewer>
Problem
The problem is if you resize the window of the application and make it smaller, the scroll bars do not react as it should. It seems to just get cut off at the edges as I make the window smaller and smaller. The horizontal scrollbar is never activated. I then made the horizontal scrollbar visible just to see what happens. But it never changes to its active form when I make the windows smaller.
Can I assume that the scrollbar only activates when the content of the allocated space becomes to large for the space and not when the space is reduced when resizing the application window? If so does anyone know a way around this?
Edit
So I was working with my code and I realize that the scroll bar for the main window works as it should when the window is resized but that is not what I want. My main application window consists of three dock panels. Each of these panels needs to have its own scrollbars. It seems that when i resize the main window, the main window's scrollbars activate as appropriate but not the individual section's scrollbars. What I want to do is disable the main windows scroll bar altogether and have only the individual section's scrollbar work.

Related

WPF Hidden ScrollViewer's Bars

I need a ScrollViewer for WPF application which like on some web pages (like Facebook), scroll bars are hidden even if content is long, but when mouse is over bars become visible. Anyone have idea how to do that?
Tnx.
MVVM focused answer:
I'm sure there is a property which allows you to hide or show the scroll bars.
Bind this property to your ViewModel.
Create a MouseOver event which fires when the mouse moves into a certain part of the screen. To do this, you could overlay an invisible grid over the screen, with the right hand 10% as the target area.
Now when the mouse enters the region, show the scrollbar, and when it exits the region, hide the scrollbar.
Ensure that you set the MinWidth on the invisible region, so that if the window gets narrow, the scrollbar trigger area is still wide enough to be usable.

Silverlight: Scrolling empty space

Situation:
I have a vertically orientated stack panel inside a ScrollViewer. The stack panel is configured to horizontally center-align its children. The scroll bar always appears at the right edge of the stack panel, which is what I want.
Then I fill the stack panel with children (user controls) of fixed widths, but all children are less wide than the stack panel. This leaves "empty space" to the left and right of the children. Visually, this does not matter, because background color is the same (which is nice).
But: In order to vertically scroll the stack panel using the mouse wheel, the mouse cursor seemingly must be positioned on top of one of the children. If the mouse cursor is positioned too much to the left or to the right (=over "empty space" in the stack panel) scrolling does not work!
Question:
How can I ensure that scrolling always works, no matter where I position the mouse cursor over the stack panel?
Martin.
Set a background on your StackPanel, any background will do. This was a known bug and this seems to fix the issue.
<StackPanel Background="White"/>
If this doesn't work, it might help to post your XAML code as it could be due to the way you have things wrapped.

Animation for SizeToContent resizing

In WPF window, I have specified SizeToContent="WidthAndHeight".
I have a number of panels stacked up, of which I change the visibility (to Visible or Collapsed) as required. My window resizes itself according to the panel that I have set visible. No issues here.
My problem is with the resizing, that the window resizes with a jerk to the final size.
I want to animate this such that the resizing is smooth. And i want to do this in my XAML file.
Is there any solution for this???
P.S. - I have not set any Width or Height property in the window and I want to restrict myself from doing that.

Silverlight 4/WPF - Nested ScrollViewer panel that scales with available screen size

In the Windows Forms world you can take a panel and set it's dock property to fill and so on with nested panels, when the user resizes the window the panels and nested panels automatically resize too. I want to achive something similar with Silverlight, here is my current structure.
Main
ScrollViewer // for body
UserControl
Grid
control
Scrollviewer // this is where my problem is
Control
The problem is I can set a size for the nested scroll viewer that looks good for 1024 resolution, but I also want to account for users that have larger resolution. If I leave it auto the content just stretches below the visible bottom line and defers to the top level ScrollViewer.
If I could achieve something analogous to how Windows Forms handles this with docking I think my problem would be solved. I must have a ScrollViewer for the nested panel and I want it to fill all visible space left. How Can I achieve this with SL4 or WPF?
[Edit]
Here is an illustration of what i'm after.
The top-level ScrollViewer allows its content to be as large as it needs to be, and adds scrollbars if that means they don't fit in the window. Its children no longer know or care how tall the window is; they just know that they've got as much space as they want.
So what is it that you want from your nested ScrollViewer? It's got all the space it needs, so it will grow to show all of its content -- there's nothing to restrict it to the height of the window. In fact, you added a top-level ScrollViewer, which specifically told it "don't restrict it to the height of the window".
If you want your inner ScrollViewer to be restricted to the window height, then take out the top-level ScrollViewer.

WPF - ScrollView Confusion

I am new to WPF and the ScrollViewer is frustrating me. Either I just don't "get" it, or it is a limited control.
Here are my Frustrations:
Bad Horizontal Scrolling The horizontal scroll bar is only visible at the bottom of the list (I have to scroll to the bottom to see it)
Bad Borders I have a ListBox in my ScrollViewer. When I start the bottom of the list has no border and when I scroll down, the top border (line) of the list box disappears. I can kind of understand this, but attempts to set BorderThickness or BorderBrush for the ScrollViewer result in no change (I wanted to use the ScrollViewer's border to keep a constatant box around the list contents, like most list boxes out in cyber world).
Bad Handling of Short Lists When the items in the list don't reach the bottom the ScrollViewer keeps the scroll bar there and just dithers it out. Why not free up some space and remove it?
Some of these may seem petty (and they are). But users expect a certain look and feel from their apps and WPF is making it hard to get this out of the box.
If you know a way to fix any of these I would love a response. If there is a better way to deal with scrolling than using the ScrollViewer that would aslo be welcome.
Maybe you see some scroll bar from inside the list rather than the scroll bar from the ScrollViewer? Try setting <ScrollViewer ... HorizontalScrollBarVisibility="Auto"> (default is Hidden, which means that no horizontal scroll bar is shown ever; also try "Visible" for the sake of debugging)
Is putting a <Border> around the ScrollViewer an option?
VerticalScrollBarVisibility has a default value of Visible. If you want the scroll bar to disappear when it is not necessary, try <ScrollViewer ... VerticalScrollBarVisibility="Auto">.

Resources