Long text in scrollable textblock is cropped - xaml

I want place long text into a textblock i´m using:
<ScrollViewer Height="auto" VerticalAlignment="Top" Width="auto">
<TextBlock TextWrapping="Wrap">
<Run Text=""/>
<LineBreak/><LineBreak/>
<Run Text=""/>
<LineBreak/><LineBreak/>
<Run Text=""/>
<LineBreak/><LineBreak/>
<Run Text=""/>
<LineBreak/><LineBreak/>
</TextBlock>
</scrollviewer>
When text is really long it is cropped, what can i do to see all text
sorry, but my english is not good

The reason for this behavior is that any element that must be displayed beyond the area which is larger than 2048x2048 pixels would be clipped by the platform.
Look at this solution.

Related

Wrap text nicely in horizontal stackpanel or wrappanel?

I've seen a few other posts about this but haven't seen anything that solves my problem. Basically, I need to have some text (bold and unbold) wrap within a Stackpanel or Wrappanel nicely. Here is a visual:
I need a combination of the two TextBlocks that you see. I've got the first bold TextBlock which contains "Title: " and then on the same line I need the next TextBlock which may or may not wrap. If it does wrap, I need the top line to stay on the top line and then wrap, as if it were all one TextBlock. Here's a made-in-Paint visual of what I need:
Here's my code that I've got so far:
<toolkit:WrapPanel Orientation="Horizontal">
<TextBlock Text="Title: " FontWeight="Bold"/>
<TextBlock TextWrapping="Wrap" Text="More text goes here " />
</toolkit:WrapPanel>
<toolkit:WrapPanel Orientation="Horizontal">
<TextBlock Text="Title: " FontWeight="Bold"/>
<TextBlock TextWrapping="Wrap" Text="More text goes here and I want it to wrap lines and go underneath the title but I can't get it to to do that. :( " />
</toolkit:WrapPanel>
Now, I'm not opposed to this being done in one TextBlock either (if possible). I know that with TextBlock.Inlines I can add a Run of bold text and then another of regular text. The problem with that is Inlines cannot be bound using MVVM (which I'm not using in this demonstration, but will be using in the final code).
So whatever the solution is, I need to be able to set the values of the TextBlocks from the code-behind so that I know it can be done with MVVM.
Does anyone know of a way to achieve this?
Use the RichTextBox control with a different run for every font style.
<RichTextBox>
<Paragraph>
<Run FontWeight="Bold">Title:</Run>
<Run>More text goes here and I want it to wrap lines and go underneath the title but I can't get it to to do that. :(</Run>
</Paragraph>
</RichTextBox>
You can bind the Text property of the Run elements to your data context, ex.:
<RichTextBox>
<Paragraph>
<Run FontWeight="Bold"
Text="{Binding Header}"></Run>
<Run Text="{Binding Text}"></Run>
</Paragraph>
</RichTextBox>
Fix Width Property of both StackPanel. this may help you. Problem is if you don't set Width Property it consider as Auto width.
<StackPanel Orientation="Horizontal" Width="400">
<TextBlock Text="Title: " FontWeight="Bold"/>
<TextBlock TextWrapping="Wrap" Text="More text goes here " />
</StackPanel >
<StackPanel Orientation="Horizontal" Width="400">
<TextBlock Text="Title: " FontWeight="Bold"/>
<TextBlock TextWrapping="Wrap" Text="More text goes here and I want it to wrap lines and go underneath the title but I can't get it to to do that. :( " />
</StackPanel >
This would helpful for you:
<toolkit:WrapPanel Orientation="Horizontal">
<TextBlock>
<Run FontWeight="Bold" Text="{Binding Header}"></Run>
<Run Text="{Binding Text}"></Run>
</TextBlock>
</toolkit:WrapPanel>
Have you tried using construction like this?
<TextBlock>
<TextBlock.Inlines>
<Bold>
<Bold.Inlines>
<Run Text="Title: "/>
</Bold.Inlines>
</Bold>
<Run Text="{Binding Text}"/>
</TextBlock.Inlines>
</TextBlock>
It works like a charm if text-block should be bound to just one block of text.

Doesnt show the full article

I have some long article to show in an view. So I made a TextBlock and bound Text with Content property.
Xaml:
<Grid Margin="12,24,12,0"
Background="White">
<TextBlock FontSize="{StaticResource PhoneFontSizeExtraLarge}"
FontFamily="{StaticResource PhoneFontFamilySemiLight}"
Foreground="Black"
Text="{Binding Column.Title}"
TextWrapping="Wrap"
Margin="0,0,0,12"
VerticalAlignment="Top" />
<ScrollViewer Margin="0,62,0,10">
<TextBlock FontSize="{StaticResource PhoneFontSizeMediumLarge}"
Text="{Binding Column.Content}"
TextWrapping="Wrap" />
</ScrollViewer>
</Grid>
The last paragrafs of the article:
The problem is that it doesn’t show the last paragraphs O_o:
What is the problem and how can I fix it?
The reason for this behavior is that any element that must be displayed beyond the area which is larger than 2048x2048 pixels would be clipped by the platform.
Maybe this article can help you : Creating Scrollable TextBlock for WP7.

Border Control in Windows Phone 7, Auto Height & Width not right

I have a ListBox with this template in it.
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="Template">
<StackPanel Margin="0,10">
<Border BorderBrush="Black" BorderThickness="1" Background="#FFFFC000" Width="460" MinHeight="76">
<StackPanel Margin="4,4,-4,-153">
<TextBlock Text="{Binding }" HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="Black" TextWrapping="Wrap"/>
<TextBlock " Text="{Binding Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="Black" TextWrapping="Wrap"/>
</StackPanel>
</Border>
</StackPanel>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
Yet I have to force set a Width and Height on the Border otherwise it makes like Width and Height of "2".
It is like it does not understand I have 2 TextBlock inside it and won't expand to fill both of them.
This leaves me with having to put a fixed height and width in what I don't like as if the text is too big it gets cutoff.
You can toss out your StackPanel's because you don't need them, they're also what's keeping your wrapping from working, you need a panel like a Grid for that. The negative Margin's also isn't something you'd normally see in a DataTemplate for a ListBox so I'd guess you have some other funky layout stuff going on from that sort of practice elsewhere up the tree.
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="Template">
<Grid Margin="0,10">
<Border BorderBrush="Black" BorderThickness="1" Background="#FFFFC000"/>
<TextBlock TextWrapping="Wrap"
HorizontalAlignment="Center" Margin="4,4,-4,-153">
<Run Text="{Binding }"/><LineBreak/>
<Run Text="{Binding Mode=OneWay}"/>
</TextBlock>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
So unless I'm missing something somewhere this should fix you up as the Grid will handle the sizes of its children for you and consume the space necessary in its parent. However if there's something else in your structure pushing stuff around and won't let it consume that space it should invoke your Wrapping.
Hope this helps :)

Layout autoscale Windows 8

I want to make a simple layout:
This is my code:
<ScrollViewer Grid.Column="1" Grid.Row="1" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled" VerticalContentAlignment="Stretch">
<StackPanel Name="MainStack" Orientation="Horizontal">
<StackPanel Width="800" Height="800" Margin="140,0,10,0" Background="#FFAC3737"/>
<StackPanel Width="400" Height="800" Margin="0,0,10,0">
<StackPanel Width="400" Height="395" Background="Black" HorizontalAlignment="Left" Margin="0,0,0,10" />
<StackPanel Width="400" Height="395" Background="Black" HorizontalAlignment="Left" />
</StackPanel>
<StackPanel Width="400" Height="800" Margin="0,0,10,0">
<StackPanel Width="400" Height="395" Background="Black" HorizontalAlignment="Left" Margin="0,0,0,10" />
<StackPanel Width="400" Height="395" Background="Black" HorizontalAlignment="Left" />
</StackPanel>
<StackPanel Width="400" Height="800" Margin="0,0,10,0">
<StackPanel Width="400" Height="395" Background="#FF5686AE" HorizontalAlignment="Left" Margin="0,0,0,10" />
<StackPanel Width="400" Height="395" Background="#FF5583AA" HorizontalAlignment="Left" />
</StackPanel>
<StackPanel Width="400" Height="800" Margin="0,0,10,0">
<StackPanel Width="400" Height="395" Background="#FF5180A8" HorizontalAlignment="Left" Margin="0,0,0,10" />
<StackPanel Width="400" Height="395" Background="#FF426E93" HorizontalAlignment="Left" />
</StackPanel>
</StackPanel>
</StackPanel>
</ScrollViewer>
Now It looks like this:
What is the best way to scale this layout to all resolutions ?
Grid is a great control for specifying how you want to use available space. I like to use * (star) sizing and think of each * as a percentage. So, if I want two columns to each take up 50 percent of the screen, their widths would be 50* and 50* (though technically as long as they're equal numbers they'll take up equal space so 1* and 1* would do the same thing).
The problem with Grid is that it tries to use all the space you give it. So, if you design a layout on a square monitor (4:3 aspect ratio) then display it on a widescreen monitor (16:9 aspect ratio) all your squares become rectangles!
You could sort of deal with this in code by monitoring whenever the size changes and making sure that the width is always some percentage of the height. But that's an ugly fix and leaves one more challenge to contend with: font size.
Many times when you're creating a very specific layout you want it to scale perfectly to all screen sizes, including text. But just because Grid adapts to the available real estate doesn't mean that the font size will automatically scale up too. That is, unless you use ViewBox.
ViewBox is an awesome control. You can put anything inside of it with a specific width and height, and as the available space for the ViewBox increases or decreases, it automatically scales everything inside of it. ViewBox maintains the correct aspect ratio for you and automatically does font scaling too!
So, start with a Grid and give it a specified width and height, then divide the rows and columns to make it look like your image above. Start at whatever width and height you want, but I suggest 1366 x 768 because that's the lowest recommended resolution for Windows 8. Finally, wrap the Grid in a ViewBox and you're done!
<ViewBox>
<Grid Width="1366" Height="768">
...
</Grid>
</ViewBox>
Dev support, design support and more awesome goodness on the way: http://bit.ly/winappsupport
I think StackPanels not the best choice for complex layout. I'd use Grid with different Width/Height ratios for different columns/rows with span columns/rows when needed. Then you will have elastic layout for every resolution.

long text cropped in textblock

I've a problem. I've a textblock and my text is cropped. It seems to appear only when the text is too long cause when the text is shorter, there is no problem.
So there is my code :
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="150" />
<RowDefinition Height="447*" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="{Binding TheContent.PathPicture}" />
<ScrollViewer Grid.Row="1">
<Grid>
<TextBlock Text="{Binding TheContent.Text}" TextWrapping="Wrap" FontSize="24" />
</Grid>
</ScrollViewer>
</Grid>
Text is croping like this :
Is the only solution to summary my content ?
The depth of a single textblock is limited to about 2000 pixels on WP7. You need to divide up your text into multiple blocks to display it all.
Controls are limited to 2k square, but there's a fairly straight forward resolution in breaking your text up and presenting the blocks in a stackpanel and wrapping that in a ScrollViewer.
Alex Yakhnin demonstrates here.
Creating Scrollable TextBlock for WP7.