Class TreeViewModel<T>
A view model for managing items in a TreeView.
Inheritance
Implements
Inherited Members
Namespace: Phoenix.BotBrain.Controls
Assembly: Phoenix.Plugin.BotBrain.Lists.dll
Syntax
public class TreeViewModel<T> : BindableBase, INotifyPropertyChanged, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, INotifyCollectionChanged where T : class
Type Parameters
Name | Description |
---|---|
T | The item type. |
Constructors
View SourceTreeViewModel(IServiceProvider?)
Initializes a new instance of the TreeViewModel<T> class.
Declaration
public TreeViewModel(IServiceProvider? serviceProvider = null)
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | serviceProvider | The service provider for creating items. |
Properties
View SourceAddItemCommand
Gets the command for adding an item.
Declaration
public DelegateCommand<object> AddItemCommand { get; }
Property Value
Type | Description |
---|---|
DelegateCommand<object> |
AddWithPopup
Gets or sets a value indicating whether or not the create button uses a popup menu of available items.
Declaration
public bool AddWithPopup { get; set; }
Property Value
Type | Description |
---|---|
bool |
AvailableItems
Gets or sets the available items to display in the create item popup menu.
Declaration
public ICollectionView? AvailableItems { get; set; }
Property Value
Type | Description |
---|---|
ICollectionView |
AvailableItemsDisplayMemberPath
Gets or sets the property name to display for items to create in the popup menu.
Declaration
public string? AvailableItemsDisplayMemberPath { get; set; }
Property Value
Type | Description |
---|---|
string |
CanAdd
Gets a value indicating whether or not items can be added.
Declaration
public bool CanAdd { get; }
Property Value
Type | Description |
---|---|
bool |
CanClear
Gets a value indicating whether or not items all items can be cleared at once.
Declaration
public bool CanClear { get; }
Property Value
Type | Description |
---|---|
bool |
ClearAllItemsCommand
Gets the command for clearing all items.
Declaration
public DelegateCommand ClearAllItemsCommand { get; }
Property Value
Type | Description |
---|---|
DelegateCommand |
Count
Gets the number of elements in the collection.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int | The number of elements in the collection. |
CreateItemFunc
Gets or sets a function for use with the AddWithPopup option to create the item selected by the user.
Declaration
public Func<object?, T?>? CreateItemFunc { get; set; }
Property Value
Type | Description |
---|---|
Func<object, T> |
IsClearable
Gets or sets a value indicating whether or not all items can be removed at once.
Declaration
public bool IsClearable { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsEditable
Gets or sets a value indicating whether or not items can be added, moved, or removed.
Declaration
public bool IsEditable { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsSorted
Gets or sets a value indicating whether or not to sort items added to the tree.
Declaration
public bool IsSorted { get; set; }
Property Value
Type | Description |
---|---|
bool |
Items
Gets the list of items.
Declaration
public List<T> Items { get; }
Property Value
Type | Description |
---|---|
List<T> |
RemoveItemsCommand
Gets the command for removing items.
Declaration
public DelegateCommand<object> RemoveItemsCommand { get; }
Property Value
Type | Description |
---|---|
DelegateCommand<object> |
RemoveSelectedItemCommand
Gets the command for removing the selected item.
Declaration
public DelegateCommand RemoveSelectedItemCommand { get; }
Property Value
Type | Description |
---|---|
DelegateCommand |
RemoveSubItemFunc
Gets or sets a function for use with the button to remove sub-items from the tree.
Declaration
public Action<T>? RemoveSubItemFunc { get; set; }
Property Value
Type | Description |
---|---|
Action<T> |
SelectedItem
Gets or sets the currently selected item.
Declaration
public T? SelectedItem { get; set; }
Property Value
Type | Description |
---|---|
T |
Services
Gets or sets the export provider used to construct a default item.
Declaration
public IServiceProvider? Services { get; set; }
Property Value
Type | Description |
---|---|
IServiceProvider |
Methods
View SourceAddItem(object)
Adds the given item.
Declaration
public void AddItem(object arg)
Parameters
Type | Name | Description |
---|---|---|
object | arg | The item identifier. |
AddItem(T?)
Adds the given item.
Declaration
public void AddItem(T? item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item. |
ClearAllItems()
Removes all items.
Declaration
public virtual void ClearAllItems()
CreateItem(object?)
Creates an item with the given identifier, or a default one.
Declaration
public T? CreateItem(object? arg = null)
Parameters
Type | Name | Description |
---|---|---|
object | arg | The item identifier. |
Returns
Type | Description |
---|---|
T | The item. |
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<T> | An enumerator that can be used to iterate through the collection. |
InsertItem(int, T?)
Inserts the given item.
Declaration
public void InsertItem(int index, T? item)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index to insert at. |
T | item | The item. |
OnCollectionChanged(NotifyCollectionChangedEventArgs)
Raises a collection changed event.
Declaration
protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
NotifyCollectionChangedEventArgs | e | The event args. |
RemoveItem(T?)
Removes the given item.
Declaration
public virtual void RemoveItem(T? item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item. |
RemoveItems(IEnumerable<T>)
Removes the given items.
Declaration
public void RemoveItems(IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | items | The items. |
SynchronizeTo<T2>(IEnumerable<T2>, Func<T, T2>, Action<T2>, Action<T2>)
Adds/removes items in the target collection, such that it matches this view.
Declaration
public void SynchronizeTo<T2>(IEnumerable<T2> target, Func<T, T2> extractItem, Action<T2> addItem, Action<T2> removeItem)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T2> | target | The target collection. |
Func<T, T2> | extractItem | A function to extract an item from the view. |
Action<T2> | addItem | A function to add an item to the target collection. |
Action<T2> | removeItem | A function to remove an item to the target collection. |
Type Parameters
Name | Description |
---|---|
T2 | The item type. |
Events
View SourceCollectionChanged
Occurs when the collection changes.
Declaration
public event NotifyCollectionChangedEventHandler? CollectionChanged
Event Type
Type | Description |
---|---|
NotifyCollectionChangedEventHandler |