| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Globalization; |
| | |
| | | |
| | | private void MultiComboBoxItem_PreviewMouseUp(object sender, MouseButtonEventArgs e) |
| | | { |
| | | if (e.OriginalSource is CheckBox) |
| | | { |
| | | // 从CheckBox点击传过来的事件要拉回焦点,不然会卡在Popup层当前的Item上 |
| | | this.Focus(); |
| | | } |
| | | if (DataContext is MultiComboBoxData data) |
| | | { |
| | | data.IsChecked = !data.IsChecked; |
| | |
| | | { |
| | | if (e.OldValue != null && e.OldValue is MultiComboBoxData oldData) |
| | | { |
| | | oldData.IsCheckedChanged -= DataIsExpandedChange; |
| | | oldData.IsCheckedChanged -= DataIsCheckedChangedChange; |
| | | } |
| | | if (DataContext != null && DataContext is MultiComboBoxData newData) |
| | | { |
| | | newData.IsCheckedChanged += DataIsExpandedChange; |
| | | newData.IsCheckedChanged += DataIsCheckedChangedChange; |
| | | } |
| | | } |
| | | |
| | | private void DataIsExpandedChange(object sender, bool IsExpanded) |
| | | private void DataIsCheckedChangedChange(object sender, bool isChecked) |
| | | { |
| | | parent.Item_IsCheckedChanged((MultiComboBoxData)sender, this, IsExpanded); |
| | | parent.Item_IsCheckedChanged((MultiComboBoxData)sender, this, isChecked); |
| | | } |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | public partial class MultiComboBox : ComboBox |
| | | { |
| | | public static readonly string[] splits = new string[] { ", " }; |
| | | |
| | | protected override DependencyObject GetContainerForItemOverride() |
| | | { |
| | | var item = new MultiComboBoxItem(this); |
| | |
| | | { |
| | | var selectedValues = SelectedValues?.ToString() ?? ""; |
| | | var showNames = this.Text?.ToString() ?? ""; |
| | | List<string> values = string.IsNullOrEmpty(selectedValues) ? new List<string>() : selectedValues.Split(',').ToList(); |
| | | List<string> names = string.IsNullOrEmpty(showNames) ? new List<string>() : showNames.Split(',').ToList(); |
| | | List<string> values = string.IsNullOrEmpty(selectedValues) ? new List<string>() : |
| | | selectedValues.Split(splits, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| | | List<string> names = string.IsNullOrEmpty(showNames) ? new List<string>() : |
| | | showNames.Split(splits, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| | | if (isChecked) |
| | | { |
| | | values.Add(data.DataValue); |