WPF Viewbox 内可使用“UniformToFill”滚动内容
如何使用 Stretch="UniformToFill"
使 WPF Viewbox
中的内容可滚动?
例如:
<Grid Height="500" Width="1000" >
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" >
<Viewbox Stretch="UniformToFill">
......
</Viewbox>
</ScrollViewer>
</Grid>
内容调整大小以填充目标尺寸,同时保留其原始宽高比。如果目标的宽高比与源的宽高比不同,则源内容将被剪裁以适合目标尺寸。
因此,我尝试使用 ScrollViewer 来滚动到被剪辑的源内容区域,但滚动条可见但被禁用。
我尝试了 ClipToBounds="False"
但没有帮助。
How could I make the content which is put inside WPF Viewbox
with Stretch="UniformToFill"
be scrollable?
For example:
<Grid Height="500" Width="1000" >
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" >
<Viewbox Stretch="UniformToFill">
......
</Viewbox>
</ScrollViewer>
</Grid>
The content is resized to fill the destination dimensions while it preserves its native aspect ratio. If the aspect ratio of the destination differs from the source, the source content is clipped to fit in the destination dimensions.
So I tried to use ScrollViewer
to be able to scroll to the areas of the source content which were clipped, but the Scrollbars are visible but disabled.
I tried ClipToBounds="False"
but it didn't help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ViewBox 根据其占据的尺寸调整其内容的大小。 ScrollViewer 为其内容提供无限的宽度/高度来渲染。因此,当您将 ViewBox 放入 ScrollViewer 中时,ViewBox 认为它具有“世界上所有的空间”可以拉伸。
此外,ViewBox 使用渲染转换来拉伸内容,这意味着您的 ScrollViewer 永远不会知道内容的最终大小。
为了使 ScrollViewer 工作,您必须在 ViewBox 上设置宽度/高度。它需要知道它占用了多少空间。
The ViewBox resizes its content based on the dimensions it occupies. The ScrollViewer gives its content infinite width/height to render. So, when you put a ViewBox inside a ScrollViewer, the ViewBox thinks it has "all the space in the world" to stretch.
Also, the ViewBox uses render transformations to stretch the content, which means your ScrollViewer will never know the final size of the content.
To make your ScrollViewer work, you have to put a Width/Height on the ViewBox. It needs to know how much space it's occupying.
我想你想要的或多或少就是这个。
What you're wanting is more or less this, I think.