Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 正在尝试将窗口的宽度和高度设置为“自动”_Wpf_Xaml_Height_Width - Fatal编程技术网

Wpf 正在尝试将窗口的宽度和高度设置为“自动”

Wpf 正在尝试将窗口的宽度和高度设置为“自动”,wpf,xaml,height,width,Wpf,Xaml,Height,Width,我正在尝试将窗口的宽度和高度设置为自动,这意味着它将合并所有子控件的宽度和高度: 我的代码: <Window x:Class="Read_360.ToastPopup" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="ToastPopup" Width="Aut

我正在尝试将窗口的宽度和高度设置为自动,这意味着它将合并所有子控件的宽度和高度:

我的代码:

<Window x:Class="Read_360.ToastPopup"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ToastPopup" Width="Auto" Height="68">
<Window.Resources>
    <ControlTemplate x:Key="MyErrorMessage"
                     TargetType="{x:Type Label}">
        <StackPanel Orientation="Horizontal"
                    Name="ErrorMessage" Width="Auto" Height="Auto">
            <Border CornerRadius="4" Width="Auto"
                    BorderThickness="0"
                    VerticalAlignment="Center"
                    Margin="4,0"
                    Background="#FF404040"
                    BorderBrush="Transparent">
                <Label Foreground="White"
                       VerticalAlignment="Center"
                       Padding="4,2"
                       Margin="4"
                       FontWeight="Bold" FontSize="15"
                       Name="Part1" Width="Auto" Height="Auto"
                       Visibility="Visible" HorizontalAlignment="Center" Content="{Binding Message}" />
            </Border>
        </StackPanel>
    </ControlTemplate>
</Window.Resources>
<StackPanel Orientation="Vertical">
    <Label Template="{StaticResource MyErrorMessage}" Name="Label1" Width="Auto" Height="Auto"></Label>
</StackPanel>

我需要宽度和高度与ControlTemplate中的标签相同

提前感谢


Din。

您应该能够在窗口上设置属性以实现此目的。

您应该能够在窗口上设置属性以实现此目的。

尝试设置属性

SizeToContent="WidthAndHeight"
但是为什么高度没有设置为自动?

尝试设置属性

SizeToContent="WidthAndHeight"

但是为什么高度没有设置为Auto.< /P>谢谢,但是现在我需要得到窗口的宽度和高度,在它的大小之后,宽度属性和StudialWalk属性显示数字0,我需要它来计算我的窗口的位置并把它放在屏幕中间。再次感谢。Windows上的WindowsStartupLocation=“CenterScreen”应该可以执行此操作;)谢谢,但现在我需要得到的宽度和高度后,窗口的大小,宽度属性和实际宽度属性显示数字0,我需要它,以计算我的窗口的位置,并把它放在屏幕中间。再次感谢。Windows上的WindowsStartupLocation=“CenterScreen”应该可以执行此操作;)