2016-10-18 13 views
4

2つのTextBlock、進行状況バー、およびキャンセルボタンを含むダイアログがあります。ここでWPFウィンドウをコンテンツに自動サイズ変更する方法

XAMLです:

Window x:Class="WpfApplication4.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:WpfApplication4" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="Auto" Width="200"> 
<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="Auto"/> 
    </Grid.RowDefinitions> 

    <TextBlock x:Name="txtFirst" Grid.Row="0" Margin="5" TextWrapping="Wrap">This is a really really really really long string that wraps</TextBlock> 
    <TextBlock x:Name="txtSecond" Grid.Row="1" Margin="5" Text="A Shorter string" TextWrapping="Wrap" MaxWidth="200"/> 
    <ProgressBar x:Name="prgProgress" Grid.Row="2" Margin="5" Height="20" /> 
    <Button x:Name="btnCancel" Grid.Row="3" Margin="5" Height="25" Width="50"/> 
</Grid> 

「私は固定の高さを持っていないウィンドウを好まないだろうが、自動車がその子のサイズに基づいて、その高さを調整し、これ以上のことができますが、これを行う方法を参照してください。ウィンドウの高さに何も割り当てていない瞬間に、コンテンツよりもはるかに高い高さを採用しているように見えます。私がWindows Height = "Auto"を設定しても、同じことが起こります。 RowDefinitionsのすべての高さは「Auto」に設定されています。これは、行の高さを行の子の高さに設定することを意味します。

事前のお手伝いがあります。

+3

「sizeToContent = "Height"? – ASh

+0

@ASh、ありがとうございました!今すぐご利用ください! – Cleve

答えて

関連する問題