Wrap TextBlock in WPF Layout

I'm trying to figure out how to do something similar to the twitter silverlight app Scott Guthrie recently demonstrated in WPF: http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone -7-twitter-application-using-silverlight.aspx

Unfortunately, it seems to me difficult to understand the wpf layout system in some fundamental way. I am trying to use various combinations of horizontal alignment / extension, width / auto at different levels of the hierarchy, and I can not get the text block "message" to turn around without assigning an explicit width.

All I want is text wrapping depending on the width of the window (or any other parent container).

<Window x:Class="TweeterWin.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" Loaded="Window_Loaded"> <ScrollViewer Height="auto" > <ListBox Name="tweetList" Height="auto" > <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Height="132"> <Image Source="{Binding Avatar}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/> <StackPanel > <TextBlock Text="{Binding User}" TextWrapping="Wrap" Foreground="#FFC8AB14" FontSize="15" /> <TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="10" /> </StackPanel> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </ScrollViewer> </Window> 

As a continuation, if anyone can post any links in my opinion, that may help me understand some of these basics of the layout. I think I understand the basic parameters of the layout (canvas, grid, glass panel, etc.), but I don’t understand why I can’t get this text block to turn around in this scenario.

Thanks!

+4
source share
2 answers

Change the horizontal glass panel to a dock or grid (I would use a dock).

This is explained by the accepted answer to this thread - the wrapper for dock panels and grids is limited in both directions, unlike the stack panel which wraps the contents in the orientation direction.

+7
source

Since you requested links to tutorials, try http://www.wpftutorial.net/ .

-1
source

Source: https://habr.com/ru/post/1307300/


All Articles