我正在尝试将窗口的宽度和高度设置为自动,这意味着它将结合其所有子控件的宽度和高度:
我的代码:
<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 内的标签相同
先谢谢了,
丁。