【问题标题】:Windows Phone Toolkit CustomMessageBox long content scrollingWindows Phone Toolkit CustomMessageBox 长内容滚动
【发布时间】:2014-02-03 09:23:25
【问题描述】:

在我的项目(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();

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回答。当我尝试将其设置为某个高得离谱的值(例如 1500)时,它不起作用,但是当我将其设置为小于全屏消息框留下的值(cca 600px - 我将其设置为 300)时,它开始工作: )
    猜你喜欢
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多