Frage

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?

War es hilfreich?

Lösung

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>

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top