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