using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using WPFluent.Extensions;
namespace WPFluent.Controls
{
///
/// 通过该类,对绑定的集合->重新创建为CheckComboBoxItem->应用默认样式
///
public class CheckComboBox : ComboBoxEx
{
#region Internal
///
/// 行选中
///
///
internal void NotifyCheckComboBoxItemClicked(CheckComboBoxItem item)
{
var itemContent = Convert.ToString(item.Content);
SelectedStrList ??= [];
SelectedObjList ??= [];
if (item.IsSelected)
{
if (!SelectedStrList.Contains(item.Content))
{
SelectedStrList.Add(itemContent);
}
if (!SelectedObjList.Contains(item.DataContext))
{
SelectedObjList.Add(item.DataContext);
}
}
else
{
if (SelectedStrList.Contains(itemContent))
{
SelectedStrList.Remove(itemContent);
}
if (SelectedObjList.Contains(item.DataContext))
{
SelectedObjList.Remove(item.DataContext);
}
}
SetCheckComboBoxValueAndContent();
}
#endregion
#region PrivateProperty
private ContentPresenter PART_ContentSite;
private System.Windows.Controls.TextBox PART_FilterTextBox;
private ICollectionView view;
private Popup PART_Popup;
private bool popupIsFirstOpen;
#endregion
#region DependencyProperty
public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register(
nameof(Content),
typeof(string),
typeof(CheckComboBox),
new PropertyMetadata(string.Empty));
///
/// 内容
///
public string Content
{
get { return (string)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register(
nameof(Value),
typeof(string),
typeof(CheckComboBox),
new PropertyMetadata(string.Empty));
///
/// 值
///
public string Value { get { return (string)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } }
#region SelectedObjList
[Bindable(true), Description("获取或者设置当前勾选项列表")]
public ObservableCollection