2009-08-25 92 views
2

有没有办法缩放视图框内容,一个控件的excpet? 我有一个网格的视框,并在这个网格中我有一些控件,我试图放大视图中的所有控件,除了一个,是否有可能?WPF视图框缩放

非常感谢, 圣保罗

回答

5

您可以使用一个网格,图层添加到您的布局。这样,您可以缩放一组项目,并将另一组项目放大。

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

视图框和XAML中其他控件的顺序取决于哪一层出现在顶部。

如果这样做并不完全符合您的要求,请发表评论,我会重新回答答案。

编辑您希望未放大的控件相对于(0,0)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