要在消息框WP8中显示的HTML代码

时间:2014-10-30 06:55:36

标签: windows-phone-8

在我的Windows Phone 8应用程序中,我在响应中收到一个html代码。设计师要求在WP8 MessageBox上显示这些数据。 是否可以或建议在Windows Phone 8自定义消息框中使用webbrowser? 还有其他方法可以实现相同的目标吗?

2 个答案:

答案 0 :(得分:1)

我只想使用Windows Phone Toolkit的自定义消息框,并使用您的自定义HTML将其内容设置为WebBrowser控件。

NuGet Windows Phone Toolkit或在此处获取:Windows Phone Toolkit

然后代码相当简单

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    // the web browser
    WebBrowser wb = new WebBrowser();
    wb.Height = 300;

    // the HTML to show inside to browser
    string my_html = "<html><head></head><body>Hello from WP8</body></html>";

    // nagivate to the HTML
    wb.NavigateToString(my_html);

    // create our Message box
    CustomMessageBox messageBox = new CustomMessageBox()
    {
        //Caption = "Allow this application to access and use your location?",
        //Message = "Sharing this information helps us provide and improve the location-based services offered for this phone. We won't use the information to identify or contact you.",
        Content = wb,
        LeftButtonContent = "allow",
        RightButtonContent = "cancel"
    };

    // show it
    messageBox.Show();

}

代码在行动

enter image description here

答案 1 :(得分:0)

您无法在标准MessageBox中使用HTML或任何格式。您需要创建一个行为类似于消息框的UserControl,您可以使用https://msptoolkit.codeplex.com/中的HTMLTextBox(或HTMLViewer)。它比WebBroser

更适合简短的HTML文本
相关问题