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?

有帮助吗?

解决方案

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>

其他提示

Try specifying negative left margin on first textBlock -

<Button Width="180" Height="55">
   <StackPanel Orientation="Vertical">
       <TextBlock Text="Item1" Margin="-70,0,0,0"/>
       <TextBlock Text="Item2"/>
       <TextBlock Text="Item3"/>
   </StackPanel>
</Button>

Output -

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top