wpf 如何固定wpf窗口的高度和宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22859573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 11:28:16  来源:igfitidea点击:

How to fix the height and the width of wpf windows

c#wpf

提问by M_M

I'm working on wpf application and i want to fix the heigth and the width of the windows . I'm using Metro style so i can't use the proprity of FormBorderStyle . I tried to use MaxWidth and MaxHeigth ( MinWidth and MinHeigth ) it works but when i excute the code a black border appears

我正在开发 wpf 应用程序,我想修复 windows 的高度和宽度。我使用的是 Metro 风格,所以我不能使用 FormBorderStyle 的属性。我尝试使用 MaxWidth 和 MaxHeigth( MinWidth 和 MinHeigth )它可以工作,但是当我执行代码时出现黑色边框

here's the code

这是代码

<Controls:MetroWindow x:Class="Selen.Wpf.DemoApplication.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns:System="clr-namespace:System;assembly=mscorlib" Title="A propos "
    MaxHeight="400" MaxWidth="550" MinHeight="400" MinWidth="550" WindowStartupLocation="CenterScreen" TitleForeground="#999988" Background="Black" 
    WindowStyle="None"  ShowMaxRestoreButton="False" SizeToContent="WidthAndHeight"  >


<Grid Background="#FF2D2D30" >
    <TabControl Width="653">
        <TabItem Header="Projet">
            <Grid Background="#FF2D2D30" Margin="0,0,-7,0">
                <TextBlock x:Name="text" Foreground="Green" TextDecorations="Underline" FontSize="16" Text="Modélidation d'une surface Topographique en 2D et 3D" Margin="10,10,204,0" Height="60" VerticalAlignment="Top" HorizontalAlignment="Center" Width="446" />
                <TextBlock x:Name="text1" Foreground="White" FontSize="14" Margin="6,75,0,196" HorizontalAlignment="Left" Text="Le domaine de Sig a connu une grande  developpement , &#xa; maintenant il est utilisé dans le domaine &#xa; de topographie pour définir les différentes surfaces &#xa; et isovaleurs contant dans  une surface terrstre" Width="407" />
                <Image x:Name="im" Margin="360,38,129,145" Source="Images/photo.jpg" Grid.Column="0" Height="184" VerticalAlignment="Center" HorizontalAlignment="Center" Width="171"/>
                <Button Width="100" Height="30" Content="Suivant" Margin="410,258,150,79" Click="button1_click" VerticalAlignment="Center" HorizontalAlignment="Center" />
            </Grid>
        </TabItem>

            <TabItem Header="Equipe"></TabItem>
        <TabItem Header="Outils"></TabItem>
    </TabControl>

</Grid>

回答by aDoubleSo

<Window ResizeMode="NoResize" Height="450" Width="650">
</Window>