本文介绍了WPF Windows大小到内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个xmal(wpf)代码,我无法使窗口大小变为内容:

hi i have this xmal(wpf) code and i cant make the window size to content:

<Window x:Class="OneSpot.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:OneSpot"
        mc:Ignorable="d"
        Title="OneSpot BETA" Height="279.195" Width="468.333" Icon="hotspot-icon.ico">
    <Grid Margin="0,0,0,-2">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="27*"/>
            <ColumnDefinition Width="88*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="btn_start" Content="start" HorizontalAlignment="Left" Margin="10,55,0,0" VerticalAlignment="Top" Width="134" Height="36" Click="btn_start_Click" Grid.ColumnSpan="2"/>
        <Button x:Name="btn_stop" Content="stop" HorizontalAlignment="Left" Margin="10,96,0,0" VerticalAlignment="Top" Width="134" Height="36" Click="btn_stop_Click" Grid.ColumnSpan="2"/>
        <Button x:Name="btn_exit" Content="exit" HorizontalAlignment="Left" Margin="10,137,0,0" VerticalAlignment="Top" Width="134" Height="36" Click="btn_exit_Click" Grid.ColumnSpan="2"/>
        <Button x:Name="btn_see" Content="see your settings" HorizontalAlignment="Left" Margin="10,178,0,0" VerticalAlignment="Top" Width="134" Height="36" Click="btn_see_Click" Grid.ColumnSpan="2"/>
        <Label x:Name="label" Content="beta" HorizontalAlignment="Left" Height="102" Margin="101.333,46,0,0" VerticalAlignment="Top" Width="199" FontSize="74.667" Grid.Column="1"/>
        <Button x:Name="btn_form2" Content="setup your Settings" HorizontalAlignment="Left" Margin="10,8,0,0" VerticalAlignment="Top" Width="134" Height="40" Click="btn_form2_Click" Grid.ColumnSpan="2"/>
        <Label x:Name="label1" Content="Copyright © reuven (MySpot)" HorizontalAlignment="Left" Margin="-1,219,0,0" VerticalAlignment="Top" FontSize="10.667" Grid.ColumnSpan="2" Width="180"/>
    </Grid>
</Window>

谢谢鲁文

Thanks reuven

推荐答案

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:wpf_2"
        mc:Ignorable="d"
        Title="MainWindow"
        SizeToContent="WidthAndHeight"
        >
    <Grid Margin="0,0,0,-2">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="27*"/>
            <ColumnDefinition Width="88*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="btn_start" Content="start" HorizontalAlignment="Left" Margin="10,55,0,0" VerticalAlignment="Top" Width="134" Height="36" Click="btn_start_Click" Grid.ColumnSpan="2"/>
        <Button x:Name="btn_stop" Content="stop" HorizontalAlignment="Left" Margin="10,96,0,0" VerticalAlignment="Top" Width="134" Height="36" Click="btn_stop_Click" Grid.ColumnSpan="2"/>
        <Button x:Name="btn_exit" Content="exit" HorizontalAlignment="Left" Margin="10,137,0,0" VerticalAlignment="Top" Width="134" Height="36" Click="btn_exit_Click" Grid.ColumnSpan="2"/>
        <Button x:Name="btn_see" Content="see your settings" HorizontalAlignment="Left" Margin="10,178,0,0" VerticalAlignment="Top" Width="134" Height="36" Click="btn_see_Click" Grid.ColumnSpan="2"/>
        <Label x:Name="label" Content="beta" HorizontalAlignment="Left" Height="102" Margin="101.333,46,0,0" VerticalAlignment="Top" Width="199" FontSize="74.667" Grid.Column="1"/>
        <Button x:Name="btn_form2" Content="setup your Settings" HorizontalAlignment="Left" Margin="10,8,0,0" VerticalAlignment="Top" Width="134" Height="40" Click="btn_form2_Click" Grid.ColumnSpan="2"/>
        <Label x:Name="label1" Content="Copyright © reuven (MySpot)" HorizontalAlignment="Left" Margin="-1,219,0,0" VerticalAlignment="Top" FontSize="10.667" Grid.ColumnSpan="2" Width="180"/>
    </Grid>
</Window>


这篇关于WPF Windows大小到内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:11