2011-07-06 32 views
1

我正在嘗試將最終用戶許可協議(EULA)放入WP7 silverlight文本塊控件中。但是,它會一直截斷我的文本。爲什麼發生這種情況? WP7 silverlight文本塊可以容納的文字大小或字符數是否有限制?Silverlight TextBlock可以容納多少個字符?

下面是我在xaml方面所做的一個例子(xaml的其餘部分是自動生成的默認值)。

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
    <ScrollViewer> 
     <TextBlock x:Name="tbMsg" TextWrapping="Wrap"/> 
    </ScrollViewer> 
</Grid> 

我也試過使用文本框,但現在,我甚至不能在文本框內滾動。我已經明確地將VerticalScrollBarVisibility設置爲可見,但我仍然無法向下滾動TextBox。實際上,我甚至沒有看到垂直滾動條。我不知道這個觀察是否因爲我仍然通過模擬器查看UI。

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
    <TextBox x:Name="tbMsg" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"/> 
</Grid> 
+0

我不認爲文字大小或限制是有限制的。但是可能會限制內存,所以如果你的文件太大,超過10mbs,那麼它可能會導致問題。您還應該嘗試將文本塊包裝在滾動面板中以啓用滾動。 –

+0

我的eula.txt文件設置爲「內容」和「不要複製」。在Windows 7上,通過查看其屬性,它的文件大小爲5.95 KB(它在磁盤上的大小不同,並顯示爲8.00 KB)。 – jake

+0

在記事本++中查看我的eula.txt,它的長度是69行和6093個字符。它以UTF-8格式保存。 – jake

回答

8

UIElement可以在任一方向(高度或寬度)上大於2048像素。不顯示任何將在此區域之外顯示的內容。 這個內容所在的空間在視覺樹中被保留。

解決此問題的方法是使用多個元素來顯示大量文本。

更新
我已經編寫了自己的解析器,用於動態顯示此類內容。理想情況下,雖然你不會在運行時使用大塊文本。當文本包含鏈接時(對其他頁面,網頁內容或電子郵件啓動器),這可能會變得更加複雜。

想要顯示EULA或任何大型文本時,您不希望讓用戶輕鬆閱讀和導航。畢竟你是包括文本​​,你希望用戶閱讀它。

如果您在設計時有文字,您應該藉此機會確保其佈置合理,並針對不同部分使用單獨的TextBlocks,適當地設置樣式標題和小標題可以幫助您做到這一點。

+0

你能給我一個關於這個方法的鏈接嗎? – jake

+0

@ user373312 - 此博文很好http://blogs.msdn.com/b/priozersk/archive/2010/09/08/creating-scrollable-textblock-for-wp7.aspx – keyboardP

+0

@matt哇,這就是我所有可以說。要做到這一點並非微不足道,正如代碼中清楚表明的那樣。感謝您的鏈接。 – jake

0

這可能是幾件事情 - 你的文字塊的高度也可以通過其他控制,您已經應用到文本的樣式可以被約束可能會導致它...

你可以發佈你的源?

+0

我修改了原始帖子。 – jake

0

我想與你分享這段代碼。它創建了許多TextBlocks並將其作爲子項添加到Stackpanel。您可以在Scroll查看器中創建一個Stackpanel,因爲Scrollvewers只能直接採用單個子元素。

//constructor 
    List<char> countStoryvar = new List<char>(); //to store the text Body 
    private string incStorybody; 
    private int textMax = 2000; //You can modify this. 

    //methods 
private void PlaceData() 
    { 
     incStorybody = "Your Story Source"; 
     int countStory = incStorybody.Count(); 
     countStoryvar = incStorybody.ToList(); 
     double countStoryd = double.Parse(countStory.ToString()); 
     if (countStoryd < textMax) 
     { 
      TextBlock txtBlock = new TextBlock(); 
      txtBlock.TextWrapping = TextWrapping.Wrap; 
      readStackPanel.Children.Add(txtBlock); 
     } 
     else 
     { 
      double countStoryd2 = countStoryd/textMax; //fetch divisions 
      countStoryd2 = Math.Round(countStoryd2, 5); //getting Real no 
      string sountstring = countStoryd2.ToString(); 
      string[] split = sountstring.Split(new string[] { "." }, StringSplitOptions.None);  //to remove decimal 
      int countStoryi = int.Parse(split[0]); 
      int remainder = countStory - (textMax * countStoryi); 
      int iterationtimestin = countStoryi + 1; 
      for (int z = 0; z < iterationtimestin; z++) 
      { 
       int zlast = countStoryi - 1; 
       int multiple = 0; 
       int multiple1 = 0; 
       int multiplecounter = 0; 
       multiple = textMax * z; 
       if (z == 0) 
       { 
        multiplecounter = textMax; 
       } 
       else 
       { 
        if (z == countStoryi) 
        { 
         multiplecounter = countStory; 

        } 
        else 
        { 
         multiple1 = z + 1; 
         multiplecounter = textMax * multiple1; 
        } 
       } 
       LoadStackPanel(multiple, multiplecounter); 
      } 
     } 

    } 
    private void LoadStackPanel(int starting, int ending) 
    { 
     TextBlock txtBlock = new TextBlock(); 
     txtBlock.TextWrapping = TextWrapping.Wrap; 
     for (int zi = starting; zi < ending; zi++) 
     { 
      incStoryInput = incStoryInput + countStoryvar[zi]; 
     } 
     txtBlock.Text = incStoryInput; 
     readStackPanel.Children.Add(txtBlock); 
     incStoryInput = string.Empty; 
    } 
相關問題