Current filter:
                                You should refresh the page.
                                  • I have the following code to implement drag drop behavior
                                    How should I tidy up the behaviourManager events ?

                                    public partial class DragNDropController : ViewController<ListView> { private BehaviorManager behaviorManager1; public DragNDropController() { InitializeComponent(); TargetObjectType = typeof(TaskResult); TargetViewType = ViewType.ListView; } protected override void OnActivated() { base.OnActivated(); View.EditorChanged += View_EditorChanged; SetupEditor(); } protected override void OnDeactivated() { View.EditorChanged -= View_EditorChanged; base.OnDeactivated(); } private void View_EditorChanged(object sender, EventArgs e) { SetupEditor(); } private void SetupEditor() { if (View.Editor == null) return; View.Editor.ControlsCreated += Editor_ControlsCreated; } private void Editor_ControlsCreated(object sender, EventArgs e) { if (!(View.Editor is GridListEditor editor) || editor.GridView == null) return; editor.GridView.GridControl.AllowDrop = false; behaviorManager1 = new BehaviorManager(); behaviorManager1.Attach<DragDropBehavior>(editor.GridView, behavior => { behavior.Properties.AllowDrop = true; behavior.Properties.InsertIndicatorVisible = true; behavior.Properties.PreviewVisible = true; behavior.DragOver += Behavior_DragOver; behavior.DragDrop += Behavior_DragDrop; behavior.BeginDragDrop += Behavior_BeginDragDrop; }); }

                                1 Solution

                                Creation Date Importance Sort by


                                Use the Controller.Deactivated event to unsubscribe from previously subscribed events and release other references and resources. I suggest that you also review C# documentation about events to learn how to correctly work with them. The following links should be helpful to you:
                                Events - C# Programming Guide | Microsoft Docs
                                Sound Code: Understanding and Avoiding Memory Leaks with Event Handlers and Event Aggregators


                                Show all comments
                                • kirsten greed 02.11.2019
                                  I cant find the controller.deactivated event
                                • kirsten greed 02.11.2019
                                  Hi Andrey
                                  Do you mean the controller OnDeactivated event?
                                  I am already using that , but I don't know how to access the behavior events in order to unsubscribe DragOver , DragDrop, BeginDragDrop
                                • kirsten greed 02.11.2019
                                  I also tried getting the behavior using GetBehavior, but it fails 
                                • Dennis (DevExpress Support) 02.12.2019

                                  My colleague meant the Controller.Deactivated  event, but you will not see it in your first screen screenshot, as expected. For more information on event handling, please refer to the Microsoft documentation links above or check for other event examples. This event is not exception and the same concept is used for it.

                                  You can also use the virtual OnDeactivated method for that purpose too, of course - it's shorter. Although this is also not directly related to XAF or DevExpress, you may find how events and virtual methods connect to each other here and in other classes from these public community resources: This is a very common pattern in .NET.

                                  If you want to necessarily unsubscribe from DragDropBehavior events here, the simplest solution would be to cache the result into a local field and then reuse it later:

                                  DragDropBehavior behaviorField = null; protected override void OnDeactivated() { View.EditorChanged -= View_EditorChanged; if(behaviorField != null) { //... behaviorField = null; } base.OnDeactivated(); } private void Editor_ControlsCreated(object sender, EventArgs e) { GridListEditor editor = View.Editor as GridListEditor; if(editor != null) { editor.GridView.GridControl.AllowDrop = false; behaviorManager1 = new BehaviorManager(); behaviorManager1.Attach<DragDropBehavior>(editor.GridView, behavior => { behaviorField = behavior; //... }); } }



                                  However, I would not even write all of this event unsubscribing code, because it is not really required here. ViewController's life cycle is the same as the ListView's control and the event is not static. Both should be destroyed and collected with no memory leaks here. I suggest you take another moment to review related concepts in public community resources like and others my colleague suggested earlier.

                                  These general concepts are not related to XAF or DevExpress controls and you would have encountered them sooner or later anyway. Understanding them earlier may save you a lot of time on XAF or non-XAF development. Since consulting and support on non-DevExpress general programming topics like this is beyond our support scope, I suggest you consider our third-party consulting services next time you require assistance with such questions For instance, as you probably know, Llamachant does offer consulting services that many our clients liked.



                                  editor.GridView.GridControl.AllowDrop = false;

                                  This will be shorter too: editor.Grid.AllowDrop = false;

                                • kirsten greed 02.12.2019
                                  Hi Dennis
                                  Thanks for the cache suggestion it works well.

                                  Out of interest , with Dave's help , I found out how to get at the Deactivated event using base.Deactivated from within the OnActivated override.... but like you say, the OnDeactivated override is easier.
                                • Dennis (DevExpress Support) 02.13.2019
                                  I am happy to hear of your results, Kirsten.