ScrollViewer ScrollBar缩小! [英] ScrollViewer ScrollBars shrink!
问题描述
大家好.
我正面临一个奇怪的问题.我实现了一个Tab控件,该控件具有一个包含Canvas的scrollviewer.
I am facing a strange problem. I have implemented a Tab Control which has a scrollviewer which contains Canvas.
问题是滚动条只是收缩(如果我单击箭头,它们仍然可以工作),有时工作得很好.我不知道为什么.
The problem is the scroll bars just shrink (they still work if I click on the arrows) and sometimes work fine. I can't figure out why.
有人遇到这样的问题吗?
Has anyone faced such a problem?
这是发生的情况的图片.
Here is a picture of what happens.
http://imageto.net/?v=scrollbar.gif
这是代码:
ScrollViewer scrollViewer = new ScrollViewer();
ScrollViewer scrollViewer = new ScrollViewer();
scrollViewer.CanContentScroll = true;
scrollViewer.CanContentScroll = true;
//滚动条会在需要时显示.
//Scroll bars appear when they are needed.
scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
scrollViewer.Background = Brushes.White;
scrollViewer.Background = Brushes.White;
scrollViewer.ScrollChanged + =新的ScrollChangedEventHandler(scrollViewer_ScrollChanged);
scrollViewer.ScrollChanged += new ScrollChangedEventHandler(scrollViewer_ScrollChanged);
//将画布设置为滚动查看器的子级.
//Set canvas as child of the scroll viewer.
scrollViewer.Content = canvas;
scrollViewer.Content = canvas;
推荐答案
通常的做法是将Grid放在ScrollViewer中,而不是Canvas中.那是因为Grid会自动扩展以适合其内容,而Canvas不会.
The normal way of doing this would be putting Grid inside a ScrollViewer, not Canvas. That's because Grid expands automatically to fit it's contents but Canvas does not.
这篇关于ScrollViewer ScrollBar缩小!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!