Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF StackPanel Layout Question

I'm trying to create a layout similar to this:

alt text http://img20.imageshack.us/img20/3533/stackn.png

Here's the code I have:

<StackPanel TextBlock.FontFamily="Segoe UI" Orientation="Horizontal">
    <StackPanel HorizontalAlignment="Stretch" Width="Auto">
        <TextBlock Padding="5,0,5,0" FontSize="12" FontWeight="Bold" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" />
        <TextBlock Padding="5,0,5,0" FontSize="12" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Id}" />
    </StackPanel>
    <StackPanel>
        <TextBlock Padding="5,0,5,0" FontSize="10" Text="Delete">
            <TextBlock.Style>
                <Style TargetType="{x:Type TextBlock}">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>    
        </TextBlock>
        <TextBlock Padding="5,0,5,0" FontSize="10" Text="Move">
            <TextBlock.Style>
                <Style TargetType="{x:Type TextBlock}">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>    
        </TextBlock>
    </StackPanel>
</StackPanel>
like image 545
RyanScottLewis Avatar asked Mar 02 '10 04:03

RyanScottLewis


1 Answers

Why don't you use a Grid for this?

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="300" />
    </Grid.ColumnDefinitions>

    <StackPanel Grid.Column="0">
        <TextBlock Text="{Binding Title}" />
    </StackPanel>

    <StackPanel Grid.Column="1">        
        <TextBlock Text="Move" />
    </StackPanel>

</Grid>
like image 169
bendewey Avatar answered Sep 17 '22 23:09

bendewey