Custom TUI Library WIP

This commit is contained in:
2023-08-08 00:27:42 +02:00
parent 7807a82f3f
commit a77d5cc235
22 changed files with 334 additions and 282 deletions

View File

@@ -0,0 +1,27 @@
using System.ComponentModel;
using TerminalUI.Controls;
namespace TerminalUI;
public class DataContextMapper<T> : IDisposable
{
private readonly IView<T> _source;
private readonly Action<T?> _setter;
public DataContextMapper(IView<T> source, Action<T?> setter)
{
ArgumentNullException.ThrowIfNull(source);
_source = source;
_setter = setter;
source.PropertyChanged += SourceOnPropertyChanged;
}
private void SourceOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != nameof(IView<object>.DataContext)) return;
_setter(_source.DataContext);
}
public void Dispose() => _source.PropertyChanged -= SourceOnPropertyChanged;
}