#930 – LineCount Property Indicates Number of Lines in TextBox

LineCount is a read-only property of a TextBox that tells you the current number of lines in the TextBox.

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Label Content="Here's a TextBox:" />
        <TextBox Name="txt1" Grid.Row="1" Margin="5"
                 HorizontalAlignment="Stretch"
                 TextWrapping="Wrap"
                 AcceptsReturn="True"
                 VerticalScrollBarVisibility="Auto"/>
        <Button Grid.Row="2" Padding="10,3"
                HorizontalAlignment="Center"
                Content="Get # Lines" Click="Button_Click"/>
    </Grid>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(txt1.LineCount.ToString());
        }

930-001