Это код: < /p>
Код: Выделить всё
public class IsEmptyChoiceValidatorBehaviour : Behavior
{
static readonly BindablePropertyKey IsEmptyPropertyKey =
BindableProperty.CreateReadOnly("IsEmpty", typeof(bool),
typeof(IsEmptyChoiceValidatorBehaviour), false);
public static readonly BindableProperty IsEmptyProperty =
IsEmptyPropertyKey.BindableProperty;
public bool IsEmpty
{
get { return (bool)GetValue(IsEmptyProperty); }
set { SetValue(IsEmptyProperty, value); }
}
protected override void OnAttachedTo(EntryChoices bindable)
{
base.OnAttachedTo(bindable);
bindable.SelectedItemChanged += Bindable_SelectedItemChanged;
}
protected override void OnDetachingFrom(EntryChoices bindable)
{
base.OnDetachingFrom(bindable);
bindable.SelectedItemChanged -= Bindable_SelectedItemChanged;
}
private void Bindable_SelectedItemChanged(object? sender,
ObservableCollection e)
{
if (e is null)
IsEmpty = true;
else
IsEmpty = (e.Count == 0);
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... the-result