Вопрос

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