WPF Viewbox 内可使用“UniformToFill”滚动内容

发布于 2024-10-25 07:59:01 字数 594 浏览 9 评论 0原文

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海之角 2024-11-01 07:59:01

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.

千と千尋 2024-11-01 07:59:01

我想你想要的或多或少就是这个。

<Viewbox Stretch="Fill" Height="800">
    <Grid Height="800">
        <ScrollViewer HorizontalScrollBarVisibility="auto" VerticalScrollBarVisibility="Disabled">
            <DockPanel>
                <dashboard:TotalizadoresControl 
                    DockPanel.Dock="Top"
                    DataContext="{Binding TotalizadoresContexto}" /> 
            </DockPanel>
        </ScrollViewer>
    </Grid>
</Viewbox>

What you're wanting is more or less this, I think.

<Viewbox Stretch="Fill" Height="800">
    <Grid Height="800">
        <ScrollViewer HorizontalScrollBarVisibility="auto" VerticalScrollBarVisibility="Disabled">
            <DockPanel>
                <dashboard:TotalizadoresControl 
                    DockPanel.Dock="Top"
                    DataContext="{Binding TotalizadoresContexto}" /> 
            </DockPanel>
        </ScrollViewer>
    </Grid>
</Viewbox>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文