Windows Phone Toolkit CustomMessageBox长内容滚动

时间:2014-02-03 09:23:26

标签: c# windows-phone-8 windows-phone-toolkit

在我的项目中( Windows Phone 8 C#/ XAML .NET 4.5应用程序)我正在使用 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();

文本没有包装或滚动。所以我尝试将它添加到textblock中:

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();

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

1 个答案:

答案 0 :(得分: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();