1
我試圖使窗口的寬度和高度是自動,這意味着將有它的所有兒童的寬度和高度控制相結合:試圖窗口的寬度和高度設置爲自動
我代碼:
<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>
我所需要的寬度和高度是相同的這是在先進的控件模板
由於內部的標籤,
Din。
謝謝,但現在我需要得到窗口的寬度和高度後,它的大小,寬度屬性和ActualWidth屬性顯示數字0,我需要它,以便計算我的窗口的位置和把它放在屏幕的中間。再次感謝。 – dinbrca 2012-08-02 09:32:54
窗口上的WindowStartupLocation =「CenterScreen」應該這樣做;) – 2012-08-02 22:47:13
再次感謝:) – dinbrca 2012-08-03 00:16:41