DataGrid vertical scrollbar problems after resizing
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 tha开发者_高级运维t 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 DataGrid
is 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 (DataGrid
content 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
精彩评论