簡體   English   中英

Windows Phone 7中的可滾動文本塊

[英]Scrollable textblock in windows phone 7

我正在嘗試創建一個可滾動的文本塊 但它似乎沒有用。 我應該怎么做呢? 以下是我的代碼:

    <Grid x:Name="ContentGrid" Grid.Row="1">
        <ScrollViewer>
        <TextBlock Height="517" HorizontalAlignment="Left" Margin="33,16,0,0" Name="textBlockRules" Text="" VerticalAlignment="Top" Width="414" FontSize="25" TextWrapping="Wrap" /></ScrollViewer>   

即使你沒有明確提到,我猜你的目的是展示一些大文字而不會被砍掉。

對於這樣的要求,stackoverflow上有一些有用的線程:1。 需要在Windows Phone 7屏幕上顯示大量文本 2.以編程方式確定文本框中的最大適合度(WP7)

另一方面,如果您想要的只是序列中的文本塊,則可以使用數據綁定到列表的ListBox。

您必須設置ScrollViewer的最大高度,並可以將滾動條的可見性設置為自動。

以下是msdn的示例:

<ScrollViewer Height="200" Width="200" HorizontalScrollBarVisibility="Auto" Canvas.Top="60" Canvas.Left="340">
<TextBlock Width="300" TextWrapping="Wrap" 
    Text="I am the very model of a modern Major-General, I've information vegetable, animal, and mineral, I know the kings of England, and I quote the fights historical, From Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical, I understand equations, both the simple and quadratical, About binomial theorem I'm teeming with a lot o' news, With many cheerful facts about the square of the hypotenuse." />
</ScrollViewer>

將scrollviewerHorizo​​ntalBar設置為visibal,使textbok伸展並確保您的文本足夠長,如下所示:

    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Name="Scroller">
        <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="100" Width="{Binding ElementName=Scroller, Path=ViewportWidth}"
        TextWrapping="Wrap" Text="Some really long text that should probably wordwrap when you resize the window." />
</ScrollViewer>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM