2

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

非常感谢,保罗

4

1 回答 1

5

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

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

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

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

编辑您希望未缩放的控件相对于Viewbox. 在这种情况下会发生这种情况,因为网格的两个孩子都在单元格 (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

于 2009-08-25T10:33:23.603 回答