我怎么能只允许一个WPF窗口统一调整大小?只允许、大小、窗口、我怎么能

由网友(护你余生无忧)分享简介:我不希望被调整我的窗口,无论是只水平或只垂直。是否有一个属性,我可以在我的窗口中设置,可以执行本,还是有一个漂亮的code隐藏的技巧,我可以使用?I don't want my window to be resized either "only horizontally" or "only vertically."...

我不希望被调整我的窗口,无论是只水平或只垂直。是否有一个属性,我可以在我的窗口中设置,可以执行本,还是有一个漂亮的code隐藏的技巧,我可以使用?

I don't want my window to be resized either "only horizontally" or "only vertically." Is there a property I can set on my window that can enforce this, or is there a nifty code-behind trick I can use?

推荐答案

您可以保留使用WPF的视框与固定的宽度和高度的内部控制内容的纵横比。

You can reserve aspect ratio of contents using WPF's ViewBox with control with fixed width and height inside.

让我们试试这个。你可以改变视框的拉伸属性来体验不同的结果。

Let's give this a try. You can change "Stretch" attribute of ViewBox to experience different results.

下面是我的screeen拍:

Here is my screeen shot:

<Window x:Class="TestWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">

    <Viewbox Stretch="Uniform">
        <StackPanel Background="Azure" Height="400" Width="300" Name="stackPanel1" VerticalAlignment="Top">
            <Button Name="testBtn" Width="200" Height="50">
                <TextBlock>Test</TextBlock>
            </Button>
        </StackPanel>
    </Viewbox>

</Window>
阅读全文

相关推荐

最新文章