1

WPFでこのウィンドウを作成する方法に苦労しています。

ウィンドウには、デザイン時に内容が不明なテキストブロックがあります。テキストブロック全体を表示するには、ウィンドウを垂直方向に拡大する必要があります

私は次のような階層を試しました:

Window (auto height)
    Stack Panel (vertical orientation)
        Text Block
        Check Box
        Grid (for precise positioning of the buttons)
            Button 1
            Button 2

これは合理的な階層ですか?これを構築するためのより良い方法はありますか?

希望するウィンドウ

4

2 に答える 2

4

あなたがしていることはうまくいくはずです。親ウィンドウでSizeToContentプロパティを使用していることを確認する必要があります。このようなもの:

XAML

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"  Width="525" SizeToContent="Height">
    <Grid Height="auto" >
        <StackPanel Orientation="Vertical" >
            <TextBlock Name="tb1" TextAlignment="Justify" TextWrapping="Wrap" Text="" />
            <Grid Height="30">
                <CheckBox VerticalAlignment="Center" Name="Random">Random CheckBox</CheckBox>
            </Grid>
            <Grid Height="auto">
                <Button Name="button1" HorizontalAlignment="Right" Margin="0,0,80,0" Width="70" Height="30" Click="button1_Click" />
                <Button Name="Button2" HorizontalAlignment="Right"  Width="70" Height="30" Click="Button2_Click" />
            </Grid>
        </StackPanel>
    </Grid>
</Window>

** CodeBehind "

private void button1_Click(object sender, RoutedEventArgs e)
    {
        tb1.Text += "TextBlock with contentes set at run-time. " + 
                     "This text block should grow in height as necessary, " + 
                     "and push the other controls down.  The window itself " +
                     "should grow to \n\n Another paragraph\n";
    }
于 2012-05-17T21:06:10.330 に答える
0

ボタンコントロールをテキストボックスのすぐ下に配置したい場合、スタックパネルが親コントロールを自動的に埋めることはありません。このレイアウトをまだ試したことがあり、問題が発生しましたか、それともこれは架空の質問ですか?

于 2012-05-17T21:04:31.740 に答える