将富文本文档作为嵌入资源加载时 UWP 挂起
UWP hangs when loading Rich Text document as embedded resource
我试图在我的应用程序中包含一些富文本,但应用程序在尝试加载文本时挂起。
// 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);
}
我试过将嵌入式资源加载到内存流中并使用它,但它也挂起。有什么想法吗?
以下是如何在 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());
我试图在我的应用程序中包含一些富文本,但应用程序在尝试加载文本时挂起。
// 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);
}
我试过将嵌入式资源加载到内存流中并使用它,但它也挂起。有什么想法吗?
以下是如何在 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());