WPF 视图框缩放

发布于 2024-08-02 18:24:34 字数 104 浏览 8 评论 0原文

除了一个控件之外,有没有一种方法可以缩放视图框内容? 我有一个带有网格的视图框,在这个网格中我有一些控件,我试图缩放视图框中除一个控件之外的所有控件,这可能吗?

非常感谢, 保罗

Is there a way to zoom a viewbox content, excpet for one control?
I have a viewbox with a grid, and in this grid I have some controls and I'm trying to zoom all the controls in the viewbox except one, is it possible?

Many thanks,
Paulo

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

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

发布评论

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

评论(1

巷雨优美回忆 2024-08-09 18:24:34

您可以使用网格向布局添加图层。这样,您可以缩放一组项目,而使另一组保持不缩放。

<Grid>
  <Viewbox>
    <!-- Controls to zoom -->
  </Viewbox>
  <!-- Control to exclude from zoom -->
</Grid>

XAML 中视图框和其他控件的顺序将取决于显示在顶部的层。

如果这不能完全满足您的要求,请发表评论,我将重新审视答案。

编辑您希望未缩放的控件相对于Viewbox的(0,0)定位。在这种情况下会发生这种情况,因为网格的两个子项都位于单元格 (0,0) 中,这意味着它们的左上角对齐。您能否举例说明 XAML 中的内容以及它有什么问题(也许编辑您原来的问题)?

下面是一些可以尝试的 XAML:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  Background="Green">
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
    <Viewbox>
      <Rectangle Fill="Yellow" Width="10" Height="10" />
    </Viewbox>
    <TextBlock>I am positioned at (0,0)</TextBlock>
    <TextBlock Margin="50,50">I am positioned at (50,50)</TextBlock>
  </Grid>
</Page>

给出如下布局:

http://img20.imageshack.us/img20/2045 /layout1m.png

但请注意,当高度减小时,网格会变得比视图框更宽,因此内容的布局如下:

http://img20.imageshack.us/img20/9397/layout2i.png

我想这不是你想要的。在这种情况下,您可以使用画布并进行如下操作:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  Background="Green">
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
    <Viewbox>
      <Rectangle Fill="Yellow" Width="10" Height="10" />
    </Viewbox>
    <Canvas>
      <TextBlock>I am positioned at (0,0)</TextBlock>
      <TextBlock Margin="50,50">I am positioned at (50,50)</TextBlock>
    </Canvas>
  </Grid>
</Page>

看起来像这样:

http://img20。 imageshack.us/img20/6743/layout3i.png

You can use a grid to add layers to your layout. That way, you can zoom one set of items, and leave another set un-zoomed.

<Grid>
  <Viewbox>
    <!-- Controls to zoom -->
  </Viewbox>
  <!-- Control to exclude from zoom -->
</Grid>

The order of the view box and the other controls in XAML will depend upon which layer appears on top.

If that doesn't quite do what you want, leave a comment and I'll revisit the answer.

EDIT You want the unzoomed control to be positioned relative to the (0,0) of the Viewbox. That will happen in this situation because both children of the grid are in cell (0,0) which means that their top-left corners are aligned. Can you give an example of what you have in XAML, and what's wrong with it (perhaps edit your original question)?

Here's some XAML to try:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  Background="Green">
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
    <Viewbox>
      <Rectangle Fill="Yellow" Width="10" Height="10" />
    </Viewbox>
    <TextBlock>I am positioned at (0,0)</TextBlock>
    <TextBlock Margin="50,50">I am positioned at (50,50)</TextBlock>
  </Grid>
</Page>

That gives a layout like this:

http://img20.imageshack.us/img20/2045/layout1m.png

But note that when the height is reduced, the grid becomes wider than the view box, and so the content is layed out like this:

http://img20.imageshack.us/img20/9397/layout2i.png

I guess that's not what you want. In that case, you use a canvas and go for something like this:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  Background="Green">
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
    <Viewbox>
      <Rectangle Fill="Yellow" Width="10" Height="10" />
    </Viewbox>
    <Canvas>
      <TextBlock>I am positioned at (0,0)</TextBlock>
      <TextBlock Margin="50,50">I am positioned at (50,50)</TextBlock>
    </Canvas>
  </Grid>
</Page>

Which looks like this:

http://img20.imageshack.us/img20/6743/layout3i.png

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