1
0

25 lines
755 B
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Avalonia.Threading;
namespace Flawless.Client;
public static class ObserverHelper
{
public static void SubscribeOnUIThread<T>(this IObservable<T> observer, Action<T> onNext)
{
var dispatcher = Dispatcher.UIThread;
observer.Subscribe(val => dispatcher.Invoke(() => onNext(val)));
}
public static void Sort<T>(this ObservableCollection<T> collection, Comparison<T> comparison)
{
var sortableList = new List<T>(collection);
sortableList.Sort(comparison);
for (int i = 0; i < sortableList.Count; i++) collection.Move(collection.IndexOf(sortableList[i]), i);
}
}