0

在我的项目(windows Phone 8 C#/XAML .NET 4.5 Application)中,我使用的是Windows Phone Toolkit

在使用 CustomMessageBox 时,我在将 CustomMessageBox 用于长文本时遇到了问题。

这是一个例子:

 CustomMessageBox box = new CustomMessageBox();
 box.content = "some really some really some really some really some really some really some really some really some really some really some really some really some really some really long text";
 box.Show();

并且文本不是包装或可滚动的。所以我尝试将其添加到文本块中:

CustomMessageBox box = new CustomMessageBox();
TextBlock txtblck = "some really some really some really some really some really some really some really some really some really some really some really some really some really some really long text";
txtblck.TextWrapping = TextWrapping.Wrap;
box.content = txtblck;
box.Show();

所以最后,文本根据我的需要换行,但还有另一个问题。如何使其可滚动 - 例如,当您有很长的文本时 - 一些长通知或法律协议等等......

我应该怎么办?我尝试将文本块添加到 ScrollViewer,但它不起作用。我可以滚动一点,但它不会保持可滚动状态,当我停止尝试向下滚动时,它会返回到起始位置。

例子:

 ScrollViewer viewer = new ScrollViewer();

 TextBlock txtInfo = new TextBlock();
 txtInfo.Text = "some long text here.....";
 txtInfo.TextWrapping = TextWrapping.Wrap;

 viewer.Content = txtInfo;

 CustomMessageBox Box = new CustomMessageBox();
 Box.Content = viewer;
 Box.Show();

如何使长文本/内容可滚动?我应该使用其他解决方案吗?

4

1 回答 1

2

您需要为高度定义一个固定值

ScrollViewer viewer = new ScrollViewer() { Height = 500 /* fixed Height */ };

TextBlock txtInfo = new TextBlock();
txtInfo.Text = @"some long text here.....";
txtInfo.TextWrapping = TextWrapping.Wrap;

viewer.Content = txtInfo;


CustomMessageBox Box = new CustomMessageBox();
Box.Content = viewer;
Box.Show();
于 2014-02-03T13:01:44.843 回答