你好,
我已经订阅了我的层到一个RowCreatedEvent。我想从ProWindow对话框中获取一些用户输入,并相应地更新新功能的属性。问题是,我在阻止RowCreatedEvent在用户有输入信息之前完全运行时遇到了麻烦。这是我当前的OnRowCreatedEvent,
public static async void OnRowCreated(RowChangedEventArgs args) {string lotCount = null;await Task.Factory.StartNew(() => {CreateLotWindow CreateLotWindow = new CreateLotWindow();createLotWindow。Owner = FrameworkApplication.Current.MainWindow;var vm = createLotWindow。DataContext作为CreateLotWindowViewModel;createLotWindow.ShowDialog ();lotCount = vm.LotCount;}, System.Threading.CancellationToken。没有,TaskCreationOptions。没有,QueuedTask.UIScheduler); // run this sequence on the UI thread Row row = args.Row; row["LOT_NO"] = lotCount; // update the row information with the userInput }
解决了!转到解决方案。
我认为问题是,你不能重用的EditOperation是启动OnRowCreated事件。另外,不建议切换和等待Row事件中的线程,因为这可能导致线程死锁。
重申一下您的工作流程:在RowCreated事件上,您需要提供一个用户界面,允许用户操作一个值,然后使用该值更新新创建行的字段值。
为了做到这一点,我不得不在OnRowEvent结束后在UI线程上启动ProWindow,然后使用单独的EditOperation来更新新创建的行。
我附上了我的示例项目,请注意它是使用C:\Data\FeatureTest\FeatureTest。aprx来自社区样本GitHub页面(Esri/ ArcGIS - Pro - SDK - Community - Samples: ArcGIS Pro SDK for Microsoft .NET Framework Community Samples)
使用样例外接程序,我可以启动我的事件监听器使用'TestChainedUpdate'按钮:
创建一个新行将触发OnRowCreated事件,在事件代码中,我记住了新创建的记录的对象id(用于以后的更新),并在UI上启动ProWindow ShowDialog:
protected void OnRowCreated(RowChangedEventArgs rowChanged) {Module1. protected voidUpdatedObjectId = rowchanged . row . getobectid ();ProApp.Current.Dispatcher.BeginInvoke (DispatcherPriority。Normal, (Action)() => {OpenPrinWindowInfoInput();}));}
所有的工作都是在OpenPrinWindowInfoInput中完成的,它在创建行之后在UI线程上执行。
代码如下:
private async void OpenPrinWindowInfoInput(){//打开对话框,填充初始数据以显示和处理结果var prowindowinfoinput = new prowindowinfoinput ();prowindowinfoinput。Owner = FrameworkApplication.Current.MainWindow;var proWinVm = new ProWindowInfoInputVM {RecordInfo = $@"已创建记录的{Module1. var prowindowswinfoinputvm {RecordInfo = $@"UpdatedObjectIdField}: {Module1。UpdatedObjectId} "};prowindowinfoinput。DataContext = proWinVm;prowindowinfoinput。关闭+= (o, e) => {System.Diagnostics.Debug。(“Pro窗口对话框关闭”);};var dlgResult = prowindowinfoinput.ShowDialog(); if (dlgResult == true) { // user click Ok: update the newly created record with info input data // load the inspector with the feature await QueuedTask.Run(() => { var insp = new Inspector(); insp.Load(_testLayer, Module1.UpdatedObjectId); insp[UpdateField] = proWinVm.InfoData; //create and execute the edit operation var op = new EditOperation { Name = "Update newly created record", SelectModifiedFeatures = false, SelectNewFeatures = false }; op.Modify(insp); op.Execute(); }); } }
在ProWindow中单击“update”后,我使用Inspector来获取新创建的记录,并在新的EditOperation中更新新创建的记录:
理想情况下,我想使用链式编辑操作在这里,但我得到了一个错误,试图创建一个链式编辑操作。然而,事务在撤销/重做堆栈上:
我认为问题是,你不能重用的EditOperation是启动OnRowCreated事件。另外,不建议切换和等待Row事件中的线程,因为这可能导致线程死锁。
重申一下您的工作流程:在RowCreated事件上,您需要提供一个用户界面,允许用户操作一个值,然后使用该值更新新创建行的字段值。
为了做到这一点,我不得不在OnRowEvent结束后在UI线程上启动ProWindow,然后使用单独的EditOperation来更新新创建的行。
我附上了我的示例项目,请注意它是使用C:\Data\FeatureTest\FeatureTest。aprx来自社区样本GitHub页面(Esri/ ArcGIS - Pro - SDK - Community - Samples: ArcGIS Pro SDK for Microsoft .NET Framework Community Samples)
使用样例外接程序,我可以启动我的事件监听器使用'TestChainedUpdate'按钮:
创建一个新行将触发OnRowCreated事件,在事件代码中,我记住了新创建的记录的对象id(用于以后的更新),并在UI上启动ProWindow ShowDialog:
protected void OnRowCreated(RowChangedEventArgs rowChanged) {Module1. protected voidUpdatedObjectId = rowchanged . row . getobectid ();ProApp.Current.Dispatcher.BeginInvoke (DispatcherPriority。Normal, (Action)() => {OpenPrinWindowInfoInput();}));}
所有的工作都是在OpenPrinWindowInfoInput中完成的,它在创建行之后在UI线程上执行。
代码如下:
private async void OpenPrinWindowInfoInput(){//打开对话框,填充初始数据以显示和处理结果var prowindowinfoinput = new prowindowinfoinput ();prowindowinfoinput。Owner = FrameworkApplication.Current.MainWindow;var proWinVm = new ProWindowInfoInputVM {RecordInfo = $@"已创建记录的{Module1. var prowindowswinfoinputvm {RecordInfo = $@"UpdatedObjectIdField}: {Module1。UpdatedObjectId} "};prowindowinfoinput。DataContext = proWinVm;prowindowinfoinput。关闭+= (o, e) => {System.Diagnostics.Debug。(“Pro窗口对话框关闭”);};var dlgResult = prowindowinfoinput.ShowDialog(); if (dlgResult == true) { // user click Ok: update the newly created record with info input data // load the inspector with the feature await QueuedTask.Run(() => { var insp = new Inspector(); insp.Load(_testLayer, Module1.UpdatedObjectId); insp[UpdateField] = proWinVm.InfoData; //create and execute the edit operation var op = new EditOperation { Name = "Update newly created record", SelectModifiedFeatures = false, SelectNewFeatures = false }; op.Modify(insp); op.Execute(); }); } }
在ProWindow中单击“update”后,我使用Inspector来获取新创建的记录,并在新的EditOperation中更新新创建的记录:
理想情况下,我想使用链式编辑操作在这里,但我得到了一个错误,试图创建一个链式编辑操作。然而,事务在撤销/重做堆栈上: