Tidied up docs and fixed several methods to be virtual

This commit is contained in:
tznind
2021-03-02 21:58:07 +00:00
parent 07899ec304
commit 62a997f4b3
3 changed files with 12 additions and 31 deletions

View File

@@ -38,13 +38,13 @@ namespace Terminal.Gui {
/// Children of the current node
/// </summary>
/// <returns></returns>
public IList<ITreeNode> Children {get;set;} = new List<ITreeNode>();
public virtual IList<ITreeNode> Children {get;set;} = new List<ITreeNode>();
/// <summary>
/// Text to display in tree node for current entry
/// </summary>
/// <value></value>
public string Text {get;set;}
public virtual string Text {get;set;}
/// <summary>
/// Optionally allows you to store some custom data/class here.
@@ -730,7 +730,7 @@ namespace Terminal.Gui {
/// Raises the <see cref="ObjectActivated"/> event
/// </summary>
/// <param name="e"></param>
protected void OnObjectActivated(ObjectActivatedEventArgs<T> e)
protected virtual void OnObjectActivated(ObjectActivatedEventArgs<T> e)
{
ObjectActivated?.Invoke(e);
}

View File

@@ -45,28 +45,20 @@ namespace UICatalog.Scenarios {
// Your data class
private class House : TreeNode {
// Your properties
public string Address {get;set;}
public List<Room> Rooms {get;set;}
// ITreeNode member:
public override IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
public IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
public override string ToString ()
{
return Address;
}
public override string Text { get => Address; set => Address = value; }
}
private class Room : TreeNode{
public string Name {get;set;}
public override string ToString ()
{
return Name;
}
public override string Text{get=>Name;set{Name=value;}}
}
private void LoadRooms()

View File

@@ -35,35 +35,24 @@ Having to create a bunch of TreeNode objects can be a pain especially if you alr
```csharp
// Your data class
private class House : TreeNode {
// Your properties
public string Address {get;set;}
public List<Room> Rooms {get;set;}
// ITreeNode member:
public override IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
public IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
public override string ToString ()
{
return Address;
}
public override string Text { get => Address; set => Address = value; }
}
// Your other data class
private class Room : TreeNode{
public string Name {get;set;}
// Rooms have no sub objects
public IList<ITreeNode> Children => new List<ITreeNode>();
public override string ToString ()
{
return Name;
}
public override string Text{get=>Name;set{Name=value;}}
}
```