private void SetBinding() { if (string.IsNullOrEmpty(this.EventName) || this.AssociatedObject == null) { return; } this.eventHandler?.Dispose(); this.eventHandler = new DynamicEventHandler(this.AssociatedObject, this.EventName, (sender, args) => { if (this.ArgumentConverter == null && this.Command != null && this.Command.CanExecute(args)) { this.Command.Execute(args); } else { var targetType = this.Command.GetType().GetGenericArguments()[0]; var convertedArg = this.ArgumentConverter.Convert(args, targetType, null, null); if (this.Command != null && this.Command.CanExecute(convertedArg)) { this.Command.Execute(convertedArg); } } }); }
private void SetEventHandler() { if (string.IsNullOrEmpty(this.EventName) || this.AssociatedObject == null) { return; } this.eventHandler?.Dispose(); this.eventHandler = new DynamicEventHandler(this.AssociatedObject, this.EventName, (sender, args) => { foreach (var item in this.Actions) { item.Invoke(args); } }); }
/// <summary> /// Occures when the behavior is attached to the object /// </summary> protected override void OnAttach() { this.AssociatedObject.AllowsColumnReorder = true; this.InheritanceContext = this.AssociatedObject.GetInheritanceContext(); // Getting Inheritance Context via Reflection is a HACK ... And will not work on native code if (this.InheritanceContext == null) { this.inheritanceContextChangedHandler = new DynamicEventHandler(this.AssociatedObject, "InheritanceContextChanged", (s, e) => { this.InheritanceContext = this.AssociatedObject.GetInheritanceContext(); this.inheritanceContextChangedHandler?.Dispose(); }); } // We have to be aware of application exit... The unload event of the controls does not // occure on application exit Application.Current.Exit += Current_Exit; Application.Current.SessionEnding += Current_SessionEnding; }