You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace AI.Models.Form
|
|
{
|
|
/// <summary>
|
|
/// 多选项条目,用于绑定 CheckBox 与 FormFieldEntry.SelectedValues 同步
|
|
/// </summary>
|
|
public class MultiSelectOptionItem : INotifyPropertyChanged
|
|
{
|
|
private readonly FormFieldEntry _entry;
|
|
private bool _isSelected;
|
|
|
|
public string Option { get; }
|
|
|
|
public bool IsSelected
|
|
{
|
|
get => _isSelected;
|
|
set
|
|
{
|
|
if (_isSelected == value) return;
|
|
_isSelected = value;
|
|
if (value)
|
|
{
|
|
if (!_entry.SelectedValues.Contains(Option))
|
|
_entry.SelectedValues.Add(Option);
|
|
}
|
|
else
|
|
{
|
|
_entry.SelectedValues.Remove(Option);
|
|
}
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public MultiSelectOptionItem(FormFieldEntry entry, string option, bool isSelected = false)
|
|
{
|
|
_entry = entry;
|
|
Option = option;
|
|
_isSelected = isSelected;
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) =>
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
}
|