diff --git a/Terminal.Gui/Views/TreeView.cs b/Terminal.Gui/Views/TreeView.cs
index 4e58a9e21..bd7e3f52b 100644
--- a/Terminal.Gui/Views/TreeView.cs
+++ b/Terminal.Gui/Views/TreeView.cs
@@ -36,10 +36,30 @@ namespace Terminal.Gui {
set { canExpandGetter = value; }
}
+ ///
+ /// private variable for
+ ///
+ object selectedObject;
+
///
/// The currently selected object in the tree
///
- public object SelectedObject {get;set;}
+ public object SelectedObject {
+ get => selectedObject;
+ set {
+ var oldValue = selectedObject;
+ selectedObject = value;
+
+ if(!ReferenceEquals(oldValue,value))
+ SelectionChanged?.Invoke(this,new SelectionChangedEventArgs(this,oldValue,value));
+ }
+ }
+
+ ///
+ /// Called when the changes
+ ///
+ public event EventHandler SelectionChanged;
+
///
/// The root objects in the tree, note that this collection is of root objects only
@@ -478,4 +498,33 @@ namespace Terminal.Gui {
///
///
public delegate bool CanExpandGetterDelegate(object model);
+
+
+ ///
+ /// Event arguments describing a change in selected object in a tree view
+ ///
+ public class SelectionChangedEventArgs : EventArgs
+ {
+ ///
+ /// The view in which the change occurred
+ ///
+ public TreeView Tree { get; }
+
+ ///
+ /// The previously selected value (can be null)
+ ///
+ public object OldValue { get; }
+
+ ///
+ /// The newly selected value in the (can be null)
+ ///
+ public object NewValue { get; }
+
+ public SelectionChangedEventArgs(TreeView tree, object oldValue, object newValue)
+ {
+ Tree = tree;
+ OldValue = oldValue;
+ NewValue = newValue;
+ }
+ }
}
\ No newline at end of file