当内容是侧面太多时,Stackpanel“打破”并且具有黑色背景

时间:2014-03-29 05:22:30

标签: c# xaml windows-phone-8

我有以下XAML:

       <ContentControl HorizontalAlignment="Left" HorizontalContentAlignment="Left" Content="{Binding TotalReviewWordBlock}" Width="465" Margin="5,10,0,5" Foreground="#FF2D2D2D"  Background="White"/>

并绑定到以下属性: -

      public StackPanel TotalReviewWordBlock
    {
        get
        {
            StackPanel st = new StackPanel();
            st.Orientation = Orientation.Horizontal;
            st.Background = new SolidColorBrush(Colors.White);
            Paragraph pgf = new Paragraph();

            Run r = new Run();
            r.Text = App.Convert("Blah ");
            r.FontWeight = FontWeights.Bold;
            r.Foreground = new SolidColorBrush(CommonLib.rgbFromHexString("#FF2D2D2D"));
            pgf.Inlines.Add(r);

            int Rating = (int)(this.userrating * 2);

            string ratingReplacement;

(属性中的一些代码......)

    Run run = new Run();
            run.Text = " " + this.myText;
            run.Foreground = new SolidColorBrush(CommonLib.rgbFromHexString("#FF2D2D2D"));
            pgf.Inlines.Add(run);

            RichTextBox rtb = new RichTextBox();
            rtb.TextWrapping = TextWrapping.Wrap;
            rtb.Width = 450;
            rtb.Blocks.Add(pgf);

            st.Children.Add(rtb);
            st.Background = new SolidColorBrush(Colors.White);
            return st;
        }
    }

问题是当文本太多(比如说多1000个字符),或者堆栈面板的高度很多时,它的背景变成黑色。就像堆栈面板一样破碎了)我之前注意到了这一点,但当时它是在一个列表框中并且有多个项目我只是简单地制作了每个项目480的宽度,使用了空白网格而不是边距,它被覆盖了## 34 ;.但这次它只是一大块文本(在段落中)。如果您需要其他信息,请告诉我。请帮忙!!

1 个答案:

答案 0 :(得分:1)

我在一个类似的&#34;黑色堆叠面板周围工作&#34;将文本拆分为段落以形成List<String>的问题。然后,该字符串列表将是ItemsSource的{​​{1}}。

因此,我选择了ListBoxStackPanel而不是非常大的ListBox

我还使用IsHitTestVisible="False"ScrollViewer.VerticalScrollBarVisibility="Disabled"

阻止了ListBox和垂直滚动中的用户互动

所以,ListBox最终结果如下:

<ListBox x:Name="listBox" IsHitTestVisible="False" ScrollViewer.VerticalScrollBarVisibility="Disabled">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border Background="White">
                <TextBlock TextWrapping="Wrap" Text="{Binding}"/>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

在代码背后:

textSplitInParagraphs = new List<String>();
// add paragraphs to the list...

listBox.ItemsSource = textSplitInParagraphs;

不知道这是否是正确的解决方法,但经过一段时间的撞击桌子后,我帮助了我。

希望这有帮助。