c# - RenderTargetBitmap.RenderAsync 导致应用无异常退出

标签 c# wpf xaml

我正在开发 Windows Phone 8.1 应用程序,我希望将一些 xaml 渲染到图像文件。

来自 this page on the RenderTargetBitmap class ,看来我的 xaml 必须连接到可视化树,所以我在屏幕外插入了元素。 在示例部分的正上方,它声明

•Content that's in the XAML visual tree but offscreen can be captured, so long as it's not Visibility=Collapsed or in the other restricted cases.

所以我认为我可以开始了...除了执行 RenderAsync 方法会导致我的应用退出而不会触发任何异常。

编辑:我试过像这样包装我的代码:

    try
    {
        await renderTargetBitmap.RenderAsync(LiveTileSource);
    }
    catch (Exception e)
    {
        throw e;
    }

通过在以 await 和 throw 开头的行上放置断点,我可以在我的应用程序中看到执行到达 RenderAsync 调用。然后应用程序可靠地退出而不会捕获任何异常。

最佳答案

MSDN 文档中 the RenderTargetBitmap page 之间存在差异和 the RenderTargetBitmap.RenderAsync page .

在第一页:

•Content that's in the XAML visual tree but offscreen can be captured

在第二页:

•Content that's in the XAML visual tree but offscreen won't be captured

它似乎因访问冲突而静默失败。

关于c# - RenderTargetBitmap.RenderAsync 导致应用无异常退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31689898/

相关文章:

c# - 如何直接绑定(bind)到 subview 模型?

wpf - 从右到左动画宽度

c# - 本地命名空间中不存在 XAML CommandBinding?

c# - 在 WPF XAML 窗口上添加图标会导致错误/崩溃 VS2012

c# - DynamoDb .AsyncSearch<T>.GetRemainingAsync 随机挂起

c# - .NET Parallel.ForEach、StreamWriter 输出 + 线程安全

c# - 解析 XML 文件中的两条连续记录

c# - 从 Task.WhenAll 获取返回值

c# - SqlException ID 无法绑定(bind)

c# - 将 Windows 窗体值发送到 wpf 控件以更新位于 wpf 控件中的属性。