Search code examples
c#wpfstackpanel

Stackpanel Layout


I have Button with StackPanel content :

<Button Width="180" Height="55">
   <StackPanel Orientation="Vertical">
      <TextBlock Text="{Binding Item.Quantity}"/>
      <TextBlock Text="{Binding Item.ItemName}"/>
      <TextBlock Text="{Binding Item.ItemSpecification/>
   </StackPanel>
</Button>

What I want to do is laying the 3 TextBlock as this:

http://alrakiza.ly/demo/stackpanel.jpg

I had tried to padding TextBlock but when padding one Textblock all Text Blocks was badding, the same thing with margin.

Can you help me to doing that?


Solution

  • HorizontalAlignment solve your problem. But parent control must set width

    <Button Height="55">
                <StackPanel Orientation="Vertical" Width="180">
                    <TextBlock Text="{Binding Item.Quantity}" HorizontalAlignment="Left"/>
                    <TextBlock Text="{Binding Item.ItemName}" HorizontalAlignment="Center"/>
                    <TextBlock Text="{Binding Item.ItemSpecification}" HorizontalAlignment="Center"/>
                </StackPanel>
        </Button>