using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace CollaborativePlatformMain.Form.UserControlForm
{
///
/// NativeCombox.xaml 的交互逻辑
///
public partial class NativeCombox : UserControl
{
///
/// 初始化渲染
///
public NativeCombox()
{
InitializeComponent();
}
///
/// 事件
///
///
///
public delegate void comboxHeand(object sender, EventArgs e);
///
/// checkboc按钮点击命令
///
public event comboxHeand UserControlComBoxClick;
///
/// 下拉按钮点击命令
///
public event comboxHeand UserControlToggleClick;
///
/// 当前 NativeCombox 选中的值
///
public List listKey;
///
/// ItemsSource属性
///
public List ItemsSource
{
get { return (List)GetValue(ItemsSourceProperty); }
set
{
SetValue(ItemsSourceProperty, value);
SetText();
}
}
///
/// ItemsSource实体属性
///
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(object), typeof(NativeCombox), new FrameworkPropertyMetadata(null, ItemsSourcePropertyChangedCallback));
///
/// ItemsSource实体属性改变事件
///
///
///
private static void ItemsSourcePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
var multioleCheckbox = dependencyObject as NativeCombox;
if (multioleCheckbox == null) return;
multioleCheckbox.CheckableCombo.ItemsSource = multioleCheckbox.ItemsSource;
}
///
/// Text属性
///
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
///
/// text标题实体
///
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(NativeCombox), new FrameworkPropertyMetadata("", TextPropertyChangedCallback));
private static void TextPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var multioleCheckbox = dependencyObject as NativeCombox;
if (multioleCheckbox == null) return;
}
///
/// 默认标题
///
public string DefaultText
{
get { return (string)GetValue(DefaultTextProperty); }
set { SetValue(DefaultTextProperty, value); }
}
///
/// 默认标题实体
///
public static readonly DependencyProperty DefaultTextProperty =
DependencyProperty.RegisterAttached("DefaultText", typeof(string), typeof(NativeCombox), new UIPropertyMetadata(string.Empty));
///
/// checkBox 选中事件
///
///
///
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
var checkbox = sender as CheckBox;
if (checkbox == null) return;
SetText();
if (UserControlComBoxClick != null)
UserControlComBoxClick(sender, new EventArgs());
}
///
/// 设置text值
///
public void SetText()
{
Text = "";
listKey = new List();
foreach (var item in ItemsSource)
{
if (item.IsSelect)
{
Text += item.Name + ",";
listKey.Add(item.Key);
}
}
Text = string.IsNullOrEmpty(Text) ? DefaultText : Text.TrimEnd(new[] { ',' });
}
///
/// 下拉按钮点击
///
///
///
private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
if (UserControlToggleClick != null)
UserControlToggleClick(sender, new EventArgs());
}
}
///
///
/// 文件名(File Name): NativeDataInfo.cs
///
/// 描述(Description): combox控件实体数据源
///
/// 数据表(Tables): nothing
///
/// 作者(Author): Li Wen Jin
///
/// 日期(Create Date): 2023年3月4日09:37:20
///
/// 修改记录(Revision History):
/// R1:
/// 修改作者:
/// 修改日期:
/// 修改理由:
///
///
public class NativeDataInfo : INotifyPropertyChanged
{
///
/// 唯一标识
///
private string key;
///
/// 唯一标识
///
public string Key
{
get { return key; }
set { key = value; }
}
///
/// 展示名称
///
private string name;
///
/// 展示名称
///
public string Name
{
get { return name; }
set { name = value; }
}
///
/// 是否选中
///
private bool isSelect;
///
/// 是否选中
///
public bool IsSelect
{
get { return isSelect; }
set
{
if (value != isSelect)
{
isSelect = value;
NotifyPropertyChanged("IsSelect");
}
}
}
///
/// 数据绑定
///
/// 唯一标识
/// 界面展示内容
public NativeDataInfo(string key, string name)
{
this.key = key;
this.name = name;
}
public NativeDataInfo()
{
}
///
/// 数据绑定
///
///
///
public NativeDataInfo(bool isSelect, string name)
{
this.name = name;
this.isSelect = isSelect;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}