在 wpf 中缩放用户控件?垂直和水平滚动条

发布于 2024-11-05 06:54:50 字数 132 浏览 2 评论 0原文

我实现了一个用户控件,但在重新缩放窗口时遇到问题。我知道当我缩小窗口时,所有内容都会缩放,每个文本框和标签也会变小。但这不是我想要的,我只是希望当我缩小屏幕时,所有内容都保持相同的大小,并且出现滚动条(垂直和水平)。我该怎么做?

谢谢

I implemented a usercontrol, but i have a problem with rescaling the window. I know when i make the window smaller, everything scales, and every textbox and label becomes also smaller. But this is not what i want, i just want that when i make the screen smaller, everything stays the same size, and that scrollbars appear ( vertical and horizontal ). How do i do that?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

恍梦境° 2024-11-12 06:54:50

假设
您描述的行为不是 WPF 的默认布局行为所必需的。这取决于您使用的布局控件。我假设您正在使用网格,并将其列和行设置为 Start (*)-GridLengths。这或多或少会产生您所描述的效果(无需缩放)。或者您可能正在使用 ViewBox,这个根据可用布局大小控制缩放整个内容。
解决方案
我想将您的整个内容包装到 ScrollViewer 可能会做你想做的事。如果没有,我建议您发布一些 XAML 代码来向我们展示您如何构建内容。

<ScrollViewer>
    <YourContent>

    </YourContent>
</ScrollViewer>

更新
如果您确实缩放您的窗口(应用 ScaleTransformation)并且您希望 UserControl 成为其中唯一不缩放的控件,则必须按照与您所做的相反的方向缩放您的 UserControl你的窗户。应用 ScaleTransformation 并将比例值设置为 1/比例。或者尝试使用 ViewBox 来放大 UserControl 的内容,但这不会很准确。

Assumption
The behaviour you describe, is not mandatory the default layout-behaviour of WPF. It depends on the layout-controls you use. I assume, you're using a Grid with setting it's columns and rows to the Start (*)-GridLengths. This would have more or less such an effect as you describe (without scaling). Or maybe you are using a ViewBox, this control scales the whole content based on the available layout size.
Solution
I guess that wrapping your whole content into a ScrollViewer will probably do what you desire. If not, I suggest that you post some XAML-code to show us how you have built your content.

<ScrollViewer>
    <YourContent>

    </YourContent>
</ScrollViewer>

Update
If you really scale your window (applying a ScaleTransformation) and you want your UserControl to be the only control within that does not scale, you have to scale your UserControl in the opposite direction as you have done it with your window. Apply a ScaleTransformation and set the scale values to 1/scale. Or try to use the ViewBox to blow up the content of your UserControl, but this will not be very exact.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文