容纳文本框WPF应用程序的高度

时间:2014-07-02 12:27:50

标签: wpf

我在WPF应用程序的网格中有一个文本框和列表视图。我想要的是,当文本溢出文本框时,listview高度应相应减少以容纳文本框。就像我们在文本框中键入WhatsApp Messenger时发生的事情一样。 这是我的代码:

 <Grid MouseDown="ShowTextBox" Height="566" VerticalAlignment="Top" Margin="10,0,40,0" Background="White" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <ListView MaxHeight="544" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" S Grid.Row="0"  Margin="20,0,0,0"  x:Name="sessionNotesList" />


            <TextBox  Grid.Row="1"  Height="Auto"  MinHeight="100" MaxHeight="554"  VerticalAlignment="Top"  Margin="20,0,30,12"  SpellCheck.IsEnabled="True"  TextWrapping="Wrap" x:Name="sessionNoteContent" KeyUp="SaveNote" LostFocus="sessionNoteContent_LostFocus"  />


        </Grid>

1 个答案:

答案 0 :(得分:1)

您是否尝试撤消Grid.RowDefinitions,以便ListView占用所有剩余空间?:

<Grid MouseDown="ShowTextBox" Height="566" VerticalAlignment="Top" Margin="10,0,40,0" Background="White" Grid.Row="1">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <ListView MaxHeight="544" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" S Grid.Row="0"  Margin="20,0,0,0"  x:Name="sessionNotesList" />
    <TextBox  Grid.Row="1"  Height="Auto"  MinHeight="100" MaxHeight="554"  VerticalAlignment="Top"  Margin="20,0,30,12"  SpellCheck.IsEnabled="True"  TextWrapping="Wrap" x:Name="sessionNoteContent" KeyUp="SaveNote" LostFocus="sessionNoteContent_LostFocus"  />
</Grid>