-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update so it works to remove a single event vs. only one when hooked …
…to the same delegate.
- Loading branch information
Showing
3 changed files
with
210 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace Eto.Forms; | ||
|
||
/// <summary> | ||
/// Helper to turn a property changed event to an EventHandler for binding | ||
/// </summary> | ||
/// <remarks> | ||
/// Use <see cref="Binding.AddPropertyEvent"/> and <see cref="Binding.RemovePropertyEvent(object,string,EventHandler{EventArgs})"/> to access | ||
/// this functionality. | ||
/// </remarks> | ||
class PropertyNotifyHelper | ||
{ | ||
public string PropertyName { get; private set; } | ||
|
||
public event EventHandler<EventArgs> Changed; | ||
|
||
public PropertyNotifyHelper(INotifyPropertyChanged obj, string propertyName) | ||
{ | ||
PropertyName = propertyName; | ||
obj.PropertyChanged += obj_PropertyChanged; | ||
} | ||
|
||
public void Unregister(object obj) | ||
{ | ||
var notifyObject = obj as INotifyPropertyChanged; | ||
if (notifyObject != null) | ||
notifyObject.PropertyChanged -= obj_PropertyChanged; | ||
} | ||
|
||
void obj_PropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName == PropertyName) | ||
{ | ||
if (Changed != null) | ||
Changed(sender, EventArgs.Empty); | ||
} | ||
} | ||
|
||
public bool IsHookedTo(EventHandler<EventArgs> eh) | ||
{ | ||
foreach (var invocation in Changed.GetInvocationList()) | ||
{ | ||
if (invocation == (Delegate)eh) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters