【问题标题】:UWP hangs when loading Rich Text document as embedded resource将富文本文档作为嵌入资源加载时 UWP 挂起
【发布时间】:2019-12-17 19:42:15
【问题描述】:

我正在尝试在我的应用中包含一些富文本,但在尝试加载文本时应用挂起。

// Here is the initiating call:
await aboutDialog.ShowAsync();

// This code hangs on the second line
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
    var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("XamlSandbox.cities.rtf");
    myRichEditBox.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, stream.AsRandomAccessStream());
}

// This code works OK
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
    var picker = new Windows.Storage.Pickers.FileOpenPicker();
    var file = await picker.PickSingleFileAsync();
    var fileStream = await file.OpenAsync(FileAccessMode.Read);
    myRichEditBox.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, fileStream);
}

我尝试将嵌入式资源加载到内存流中并使用它,但这也挂起。有什么想法吗?

【问题讨论】:

    标签: file-io uwp embedded-resource


    【解决方案1】:

    这是在 UWP 中正确加载嵌入资源的方法:

                var rtfUri = new Uri("ms-appx:///cities.rtf");
                var file = await StorageFile.GetFileFromApplicationUriAsync(rtfUri);
                var stream = file.OpenAsync(FileAccessMode.Read);
                myRichEditBox.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, stream.GetResults());
    

    【讨论】:

    • 很高兴看到您解决了这个问题,请将其标记为答案,以便帮助更多人
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    相关资源
    最近更新 更多