我怎么能只允许一个WPF窗口统一调整大小? [英] How Can I Only Allow Uniform Resizing in a WPF Window?

查看:146
本文介绍了我怎么能只允许一个WPF窗口统一调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望被调整我的窗口,无论是只水平或只垂直。是否有一个属性,我可以在我的窗口中设置,可以执行本,还是有一个漂亮的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>

这篇关于我怎么能只允许一个WPF窗口统一调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆