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
- {
-
-
-
- public partial class NativeCombox : UserControl
- {
-
-
-
- public NativeCombox()
- {
- InitializeComponent();
- }
-
-
-
-
-
- public delegate void comboxHeand(object sender, EventArgs e);
-
-
-
- public event comboxHeand UserControlComBoxClick;
-
-
-
- public event comboxHeand UserControlToggleClick;
-
-
-
- public List<string> listKey;
-
-
-
- public List<NativeDataInfo> ItemsSource
- {
- get { return (List<NativeDataInfo>)GetValue(ItemsSourceProperty); }
- set
- {
- SetValue(ItemsSourceProperty, value);
- SetText();
- }
- }
-
-
-
- public static readonly DependencyProperty ItemsSourceProperty =
- DependencyProperty.Register("ItemsSource", typeof(object), typeof(NativeCombox), new FrameworkPropertyMetadata(null, ItemsSourcePropertyChangedCallback));
-
-
-
-
-
- private static void ItemsSourcePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
- {
- var multioleCheckbox = dependencyObject as NativeCombox;
- if (multioleCheckbox == null) return;
- multioleCheckbox.CheckableCombo.ItemsSource = multioleCheckbox.ItemsSource;
- }
-
-
-
- public string Text
- {
- get { return (string)GetValue(TextProperty); }
- set { SetValue(TextProperty, value); }
- }
-
-
-
- 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));
-
-
-
-
-
- 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());
- }
-
-
-
- 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[] { ',' });
- }
-
-
-
-
-
- private void ToggleButton_Click(object sender, RoutedEventArgs e)
- {
- if (UserControlToggleClick != null)
- UserControlToggleClick(sender, new EventArgs());
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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));
- }
- }
- }
|