views:

36

answers:

2

Hi,

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!

A: 

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>
JSprang
I've tried your code in a child window. It renders well in the XAML designer. At run-time however, the child window fills the whole screen (horizontally). Workaround: set a fixed width/height on the ChildWindow control..which isn't great. I haven't found a way to make it work without hard-coding dimensions..(setting the second column's width works too).
AlexB
A: 

How about using Border instead with a height of 1

David
Yep..That works! (inside a grid, not a StackPanel)
AlexB
It'll work in a stack panel too, you probably just need to set the size. The grid is probably setting up the border width for you.
Jason Jackson
add HorizontalAlignment="Stretch" to the stackpanel
David