SMM
SMM

Reputation: 201

How to display in a StackPanel the TextBlock vertically and horizontally?

I have a ListView with some elements. For each item I insert an image, the name of the object and one of the properties.

I set the horizontal orientation of the stackpanel.

Displays the image on the left, on the right is the name of the object.

I wanted to then display the property under the name, always to the right of the image. How do I, if the StackPanel I set it horizontally?

 <StackPanel Orientation="Horizontal">
     <Image Source="Assets/rsz_1rsz_museumiclip.jpg"/>
     <TextBlock Text=""/>
     <TextBlock Text="{Binding Path=NomeMuseo}" FontSize="26"/>
     <TextBlock Text="{Binding Path=Paese}"/>//THIS IS
 </StackPanel>

Upvotes: 1

Views: 505

Answers (1)

BradleyDotNET
BradleyDotNET

Reputation: 61379

Since DockPanel isn't an option, I would just use Grid. It will let you precisely control that kind of layout:

<Grid>
   <Grid.RowDefinitions>
      <RowDefinition Width="Auto"/>
      <RowDefinition Width="Auto"/>
   </Grid.RowDefinitions>
   <Grid.ColumnDefinitions>
      <ColumnDefinition Height="Auto"/>
      <ColumnDefinition Height="20"/>
   </Grid.ColumnDefinitions>
     <Image Source="Assets/rsz_1rsz_museumiclip.jpg"/>
     <TextBlock Text=""/>
     <TextBlock Text="{Binding Path=NomeMuseo}" FontSize="26" Grid.Row="0" Grid.Column="1"/>
     <TextBlock Text="{Binding Path=Paese}" Grid.Row="1" Grid.Column="1"/>
</Grid>

Alternatively, you could use two StackPanels as ChrisW suggested. Its a little easier to set up, but you lose some control.

<StackPanel Orientation="Horizontal">
   <Image Source="Assets/rsz_1rsz_museumiclip.jpg"/>
   <StackPanel>
       <TextBlock Text="{Binding Path=NomeMuseo}" FontSize="26"/>
       <TextBlock Text="{Binding Path=Paese}"/>
   </StackPanel>
</StackPanel>

Upvotes: 1

Related Questions