1
我有以下代碼,使StackPanel的高度是它的寬度的1.4倍。爲什麼StackPanel的高度設置爲自動時,其高度設置爲從後面的代碼
C#:
private void AutoRun()
{
//Page height
double PageHeight = Window_1_Document_Page_1.Width * 1.4;
Window_1_Document_Page_1.Height = PageHeight;
}
XAML:
<StackPanel Name="Window_1" BorderBrush="Black" BorderThickness="1" Grid.Row="0" Grid.Column="0">
<Grid BorderThickness="0,0,0,1" BorderBrush="Black">
<TextBlock FontSize="18" Name="Window_1_Title" Padding="5">New Document 1</TextBlock>
<Button HorizontalAlignment="Right" Name="Window_1_Close" Content="Close Window" Visibility="Collapsed" Click="CloseWindow_Click"/>
</Grid>
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled">
<Grid Name="Window_1_Document_Page_1" Margin="20" BorderThickness="1" BorderBrush="Black" Padding="10">
<TextBox Name="TextBox1" AcceptsReturn="False" BorderBrush="Transparent" BorderThickness="0" FontFamily="Calibri" FontSize="16" Height="Auto" Width="Auto" TextWrapping="Wrap" Text="{Binding ElementName = Window_1_Document_Page_1, Path = ActualWidth}" />
</Grid>
</ScrollViewer>
</StackPanel>
然而,StackPanel的Window_1_Document_Page_1
呈現爲如果它的高度爲Auto
。
可能有人請告訴我如何解決這個問題?
嘗試內的StackPanel改變電網有2行。其中第一排高度=自動,第二排高度= * –