DataGrid vertical scrollbar problems after resizing - silverlight

I'm working with a DataGrid in Silverlight.
If I have enough items so that the vertical scroll bar is visible for all sizes of the window, and I re-size the window a few times, the vertical scroll gets out of sync. The thumb gets to small as if the control thinks that there are more items then it is. When I drag the thumb towards the bottom or the top, the content starts to jump. It happens all the time, very frustrating. The DataGridis laying within a DockPanel that is re-sized according how large the window is (no specific size that is)
Anyone have any ideas?

I have some similar issues. Most of them could be resolved by calling UpdateLayout on the datagrid.
I too have a datagrid in a dockpanel. When I scroll down and select the bottom record and then reload my datagrid the horizontal scrollbar seems to cover the last record. And the vertical scrollbar appears to be as far down as possible and cannot be dragged down further.
If i use the scrollwheel on the mouse the last record can be brought into view.
This only occurs when i show my application in a maximized window.
Have you gotten anywhere with this?

I tried similar approach with the derived DataGrid.
The difference is that the OnApplyTemplate would only get the instance of VerticalScrollbar and the separate public method was introduced to invoke the UpdateLayout() on the scroll bar. Such method is to be called explicitly in the situations that may bring the scroll bar size out of sync (DataGridcontent resizing, etc.)
Sometimes the UpdateLayout() alone was not enough so I added flipping the scroll bar visibility - that worked better though still not in 100% of situations

This is a bug in the datagrid. You can solve this by inheriting from the datagrid and on the OnApplyTemplate method you search for the scrollbars and manually update their layout:
public override void OnApplyTemplate()
{
verticalScrollBar = this.GetTemplateChild("VerticalScrollbar") as ScrollBar;
if (verticalScrollBar != null)
{
verticalScrollBar.UpdateLayout();
}
}
If this still doesn't work then try calling the OnApplyTemplate method manuallty in code.

In data grid Style remove the vertical scroll bar and follow the Below Steps
Step1: Sorround the DataGridRowsPresenter with Scroll Viewer
Step2: Make HorizantalScrollBarVisibility to Disable
Step3: VerticalScrollBarVisibility to Auto

Related

How can you stop a Winforms Panel from scrolling with Override a Class?

I'm dealing with an 'old' problem, the scroll position from a Panel is reset when returning to the application after leaving it.
I've got a DataGridView on a Panel, for the Panel the AutoScroll = True, so when the DataGridView is wider as the panel the horizontal scrollbar will appear.
When the user scrolls the Panel to a certain scroll position and leave the application, when returning to the application the scrollbar position is reset to the beginning.
I found several posts describing this behavior, one of the solutions that people talk about is: 'There is an overrideable ScrollToControl method in the ScrollableControl now. Replace the call to the base class implementation to return DisplayRectangle.Location and problem solved'
See: http://seewinapp.blogspot.com/2005/09/is-your-autoscroll-too-auto.html
I can not get to the right solution, how can I override the base class?
Can I override the base class when the panel is not placed programmatically?
I've already tried several things, almost tried every event to catch and set the scroll position to the value when the form is deactivated.
Please point me in the right direction, thanks in advance!

Enable WPF DataGrid Panning?

I have a WPF DataGrid that I allow to expand vertically as far as needed, and so there is no need to scroll or pan the content within the DataGrid itself. However, it's inside of a Window that has a ScrollViewer.
When I run it, the DataGrid grows vertically to allow all rows as expected, and the ScrollBar along the edge of the Window appears as expected. But I can only touch/pan up and down if I do it on the areas of the Window that lie outside of the DataGrid itself. The DataGrid accepts and effectively blocks the input (which is not unexpected.)
So how can I make the DataGrid "pass" this touch/pan input upward to it's container, i.e. the Window, so that the Window will know it needs to scroll?
I might be wrong here, but I thought the visual tree in WPF bubbles upwards. This would mean that your DataGrid, as I am interpreting it right now, would capture the event and handle it correctly as you mentioned.
But once that's done, it bubbles up to its parent (the window) thus not passing the event to your scrollviewer. It does this because the datagrid in scrollviewer are probably siblings instead of having a parent/child relationship.
One option would be to setup a command to handle this behaviour.
Or you could use the dispatcher:
this.Dispatcher.Invoke( () =>
control.ScrollToVerticalOffset(scrollViewerChannelBtns.VerticalOffset + 50);
In xaml
ScrollViewer.PanningMode="Both"

How to make a ListBox control scroll automatically and smoothly in Silverlight

Some say I can use ScrollIntoView method to deal with this issue, but ScrollIntoView can only scroll the ListBox logically, not physically.Is there any way to make a ListBox scroll automatically, and seems like someone is dragging its scroll-bar smoothly.
You can use a ScrollViewer instead of ListBox. ScrollViewer has ScrollToVerticalOffset(Double offset) and ScrollToHorizontalOffset(Double offset) methods which you can use to scroll it automatically.

How to enable scrollbar / scrolling on a WPF Datagrid

I've got a DataGrid control that's within a Grid layout container, and I can't seem to get the auto-scroll on the DataGrid itself to work. I can wrap the DataGrid around a ScrollViewer and thus adding the scroll bar, but the auto scrolling doesn't work.
So right now, when new entries are added to the DataGrid, the DataGrid just expands vertically. I'd like to have the vertical scroll bar enabled allowing scrolling to the items in the DataGrid when more items are added than the original vertical size can show, instead of the whole DataGrid expanding. Surely there's got to be an easy way to make that happen.
Okay, got this one figured out ... It turns out I didn't even need to wrap the datagrid around a ScrollViewer after all. All I had to do is define the height for the datagrid (Using the "Height" attribute) and the datagrid scroll bar appears when items are added that go beyond the height. Apparently when the height isn't defined it is dynamic and expands vertically as new items are added.
Another thing to add to this was that in my datagrid, I had a row details defined for each row as well, so when multiple row details were expanded, the scrolling would be enabled, but the scroll bar behavior was a little wacky (Like it wasn't smooth scrolling), and the fix for that to make it smooth scrolling was adding the following datagrid attribute: ScrollViewer.CanContentScroll="False" (I'm guessing the datagrid control is/inherits from a ScrollViewer) and then the scrolling was smooth and like the normal expected scrolling behavior.

WinForm Panel scrolling without a scrollbar?

I'm creating a User Control that's basically a Panel (with random content inside), and I need to be able to scroll up and down this Panel using buttons (up and down) rather than the scrollbar.
The reason I have to do it this way is because the program will be used on a touch screen monitor and we need big buttons rather than an ugly little scrollbar.
I've been messing around with the VerticalScrollbar properties, and none of them seem to do anything. I've noticed that if I set AutoScroll to false, AutoScrollPosition actually shows coordinates, except negative of what it should be. Also, I've noticed that panel.VerticalScrollbar.Visible = true; only seems to work when placed outside of the constructor. Is there a reason for that?
Basically, WinForms' scrollbars are very confusing (buggy?) to me. Does anyone know a good way to scroll up and down a panel programmatically with buttons (I don't care if I need to have an invisible scrollbar).
Thank you! =D
Make your UserControl a regular UserControl (i.e inherit from UserControl instead of Panel) and place a Panel on your UserControl. Put any content/controls on the inner Panel, and then change the Panel's Left and Top properties to move it around without scrollbars. You could also add buttons to your UserControl to handle the movement of the inner Panel.
A simpler way, however, might be to just use really wide/high scrollbars, and set their Thumbwidth (I think this is the property) to the same large value - this will produce scrollbars that are easy to use with the fingers. To my knowledge there's no way to do this with the scrollbars that appear on a Panel with Autoscroll set to True, so you'd still need to use the method I mentioned above (with an inner Panel sitting on your UserControl) and add the scrollbars to move it yourself.
I agree that scrollbars in Windows suck, so while I'm normally in favor of just using the standard controls that everyone is used to, I don't see anything wrong with rolling your own in this case.

Resources