c - 连续操作 inkstrorkecontainer.clear() 和 addstrokes() 导致 UWP 中的 EXCEPTION
问题描述
Sink1 是一个 inkstroke 容器,它不绑定到 inkcanvas(我也尝试将其绑定到 inkcanvas 以避免异常,但仍然没用)。ink1 是 xaml 上的 inkcanvas。
public sealed partial class wpage : Page
{
public wpage()
{
this.InitializeComponent();
ink1.InkPresenter.StrokeContainer = inkStrokeContainer1;
ink1.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;
ink1.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Mouse;
}
public void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
{sink1.Clear();
sink1.AddStrokes(args.Strokes);
}
}
above code will cause an
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
我也试过:
public async void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
{ await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, new DispatchedHandler(() =>
{ {sink1.Clear();
sink1.AddStrokes(args.Strokes);
});
}
但还是没用还用炸弹
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break(); .
我还尝试在 taks.run 和 Dispatcher.RunAsync 中同时运行它们,也同样是炸弹。我这样做是因为我需要用 inkstrokecontainer 类中的 save 方法序列化 isf 格式的 inkstroke,用其他方法序列化结果大小太大。
解决方案
Sink1 是一个 inkstroke 容器,它不绑定到 inkcanvas
这就是问题的原因。
sink1
和ink1.InkPresenter.StrokeContainer
不一样InkStrokeContainer
,也就是说Stroke
inInkCanvas
不能直接加到另一个StrokeContainer
上。
您可以尝试修改您的代码:
private void InkPresenter_Collect(InkPresenter sender, InkStrokesCollectedEventArgs args)
{
sink1.Clear();
foreach (var item in args.Strokes)
{
sink1.AddStroke(item.Clone());
}
}
简单来说,Stroke
屏幕上已经显示的属于ink1
,不能添加到另一个InkStrokeContainer
,但是可以获取它的克隆对象,克隆的对象不属于ink1
,可以添加。
此致。
推荐阅读
- kubernetes - 如何从一台 linux 机器访问另一台主机上的 k8s
- node.js - 尝试启动反应应用程序时出错
- python - Beautifulsoup get_text()函数不起作用
- python-3.x - ModuleNotFoundError:没有名为“astor”的模块
- node.js - Nestjs 在容器启动时退出
- machine-learning - 权重初始化的预训练深度学习模型
- javascript - 将 Node JS 请求转换为 API 以响应 Fetch 语法
- flutter - Flutter 打不开文件路径
- javascript - 如何在导出属性中获取表属性“名称”到文件名 DataTables
- php - PHP中路由的条件