/
anna_grinchenko
/
ReactiveUISample
Обзор
Документация
Войти
/
anna_grinchenko
/
ReactiveUISample
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ViewModels/ContactGroupViewModel.cs
42 строки
1 KB
GrinchenkoAnna
Можно отредактировать группу по ключу. Контакты получают полный префикс, группа - первую букву префикса
06 июл 2026, 15:26
06 июл 2026, 15:26
5ffebbb
Код
Авторство
О чём код?
using DynamicData.Binding; using ReactiveUI; using ReactiveUI.SourceGenerators; using System.Linq; namespace ReactiveUISample.ViewModels { public partial class ContactGroupViewModel : ReactiveObject { public string Key { get; private set; } public ObservableCollectionExtended<ContactViewModel>? Items { get; } public MainWindowViewModel Owner { get; } [Reactive] private string _editedKey; public ContactGroupViewModel(string key, ObservableCollectionExtended<ContactViewModel>? items, MainWindowViewModel owner) { Key = key; EditedKey = key; Items = items; Owner = owner; } public void ApplyNewKey(string newKey) { foreach (var contact in Items.ToList()) { var name = contact.Name; if(name.Length > 2 && name[1] == '_') name = name[2..]; else if (name[0] == '#') name = name[1..]; contact.Name = newKey == "#" ? "#" + name : newKey + "_" + name; Owner.UpdateContactInCache(contact); } Key = newKey; EditedKey = newKey; } } }