Alex B
Alex B

Reputation: 644

Display a line after a TextBlock in Silverlight

I'm working on a dataform in Silverlight 4 and would like to group elements by section, with a title for each. The title consists of a TextBlock followed by a horizontal line. The line runs until the edge of the form.

I've tried the following (from this thread: http://forums.silverlight.net/forums/p/77813/183885.aspx), without success:

<StackPanel Orientation="Horizontal"/>
    <TextBlock Text="Section title" />
    <Line X1="0" Y1="0" X2="1" Y2="0" Stretch="Fill" Stroke="Black" />
</StackPanel>

Any idea why this isn't working?

Thanks!

Upvotes: 2

Views: 6863

Answers (2)

David
David

Reputation: 550

How about using Border instead with a height of 1

Upvotes: 7

JSprang
JSprang

Reputation: 12909

I was curious about your post, so I tried it for myself. I was unable to get the line to stretch also when using a StackPanel. Although, I was able to get it to work with a Grid:

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="20"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>

    <TextBlock Grid.Row="0" Grid.Column="0" Text="Section title" HorizontalAlignment="Right" VerticalAlignment="Center" />
    <Line Grid.Row="0" Grid.Column="1" X1="0" Y1="0" X2="1" Y2="0" Stretch="Fill" Stroke="Black" StrokeThickness="1" />
</Grid>

Upvotes: 0

Related Questions