/
anna_grinchenko
/
ReactiveUISample
Обзор
Документация
Войти
/
anna_grinchenko
/
ReactiveUISample
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
Controls/ContactCard.cs
84 строки
3 KB
GrinchenkoAnna
Можно отредактировать группу по ключу. Контакты получают полный префикс, группа - первую букву префикса
06 июл 2026, 15:26
06 июл 2026, 15:26
5ffebbb
Код
Авторство
О чём код?
using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using ReactiveUISample.AttachedProperties; using ReactiveUISample.Behaviors; using System; using System.Linq; using System.Reactive.Linq; namespace ReactiveUISample.Controls; public partial class ContactCard : TemplatedControl { private Border? _partBorder; private TextBlock? _partIcon; public ContactCard() { } protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); _partBorder = e.NameScope.Find<Border>("PART_Border"); _partIcon = e.NameScope.Find<TextBlock>("PART_Icon"); this.GetObservable(NameProperty) .Select(name => (name?.Length ?? 0) > 20) .Subscribe(isImportant => IsImportant = isImportant); this.GetObservable(ContactCardProperties.IsNewProperty) .Subscribe(isNew => { if (_partBorder is not null) { if (isNew) _partBorder.Classes.Add("new"); else _partBorder.Classes.Remove("new"); } }); this.GetObservable(ContactCardProperties.IsOnlineProperty) .Subscribe(isOnline => { if (_partBorder is not null) { if (isOnline) _partBorder.Classes.Add("online"); else _partBorder.Classes.Remove("online"); } }); _partBorder?.GetObservable(DragDropHelper.IsDraggingProperty) .Subscribe(isDragging => { _partBorder.Opacity = isDragging ? 0.5 : 1; }); } public string Name { get => GetValue(NameProperty); set => SetValue(NameProperty, value); } public static readonly StyledProperty<string> NameProperty = AvaloniaProperty.Register<ContactCard, string>(nameof(Name), defaultValue: string.Empty); public string Email { get => GetValue(EmailProperty); set => SetValue(EmailProperty, value); } public static readonly StyledProperty<string> EmailProperty = AvaloniaProperty.Register<ContactCard, string>(nameof(Email), defaultValue: string.Empty); public bool IsSelected { get => GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); } public static readonly StyledProperty<bool> IsSelectedProperty = AvaloniaProperty.Register<ContactCard, bool>(nameof(IsSelected), defaultValue: false); public bool IsImportant { get => GetValue(IsImportantProperty); set => SetValue(IsImportantProperty, value); } public static readonly StyledProperty<bool> IsImportantProperty = AvaloniaProperty.Register<ContactCard, bool>(nameof(IsImportant), defaultValue: false); }