命令更新
This commit is contained in:
@@ -355,8 +355,7 @@ public class MultiComboBox : Control
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
if (listBox != null)
|
||||
listBox.SelectionChanged -= ListBox_SelectionChanged;
|
||||
listBox?.SelectionChanged -= ListBox_SelectionChanged;
|
||||
|
||||
listBox = GetTemplateChild("PART_ListBox") as ListBox;
|
||||
filterTextBox = GetTemplateChild("PART_FilterTextBox") as TextBox;
|
||||
@@ -564,8 +563,7 @@ public class MultiComboBox : Control
|
||||
private static void OnSelectionModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var c = (MultiComboBox)d;
|
||||
if (c.listBox != null)
|
||||
c.listBox.SelectionMode = c.SelectionMode;
|
||||
c.listBox?.SelectionMode = c.SelectionMode;
|
||||
|
||||
c.isUpdatingSelection = true;
|
||||
try
|
||||
@@ -620,7 +618,7 @@ public class MultiComboBox : Control
|
||||
// 1. 移除 ListBox 中有但源中没有的 (倒序遍历以安全删除)
|
||||
for (int i = controlList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (!sourceSet.Contains(controlList[i]))
|
||||
if (!sourceSet.Contains(controlList[i]!))
|
||||
{
|
||||
controlList.RemoveAt(i);
|
||||
}
|
||||
@@ -763,13 +761,13 @@ public class MultiComboBox : Control
|
||||
}
|
||||
|
||||
// 处理第一个元素
|
||||
if (IsMatch(firstItem, filter!, propDesc)) filtered.Add(firstItem);
|
||||
if (IsMatch(firstItem, filter!, propDesc)) filtered.Add(firstItem!);
|
||||
}
|
||||
|
||||
// 处理剩余元素
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
if (IsMatch(enumerator.Current, filter, propDesc))
|
||||
if (IsMatch(enumerator.Current, filter!, propDesc))
|
||||
filtered.Add(enumerator.Current);
|
||||
}
|
||||
|
||||
@@ -791,6 +789,6 @@ public class MultiComboBox : Control
|
||||
value = item.ToString();
|
||||
}
|
||||
|
||||
return value != null && value.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
return value != null && value.Contains(filter);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace Melskin.Controls
|
||||
/// </summary>
|
||||
public class SearchableComboBox : ComboBox
|
||||
{
|
||||
private TextBox editableTextBox;
|
||||
private TextBox? editableTextBox;
|
||||
private bool isInternalOperation;
|
||||
|
||||
static SearchableComboBox()
|
||||
@@ -31,11 +31,13 @@ namespace Melskin.Controls
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
if (GetTemplateChild("PART_EditableTextBox") is TextBox _editableTextBox)
|
||||
editableTextBox = GetTemplateChild("PART_EditableTextBox") as TextBox;
|
||||
|
||||
if (editableTextBox != null)
|
||||
{
|
||||
_editableTextBox.TextChanged += OnEditableTextBoxTextChanged;
|
||||
editableTextBox.TextChanged += OnEditableTextBoxTextChanged;
|
||||
// 点击时全选
|
||||
_editableTextBox.GotFocus += (s, e) => _editableTextBox.SelectAll();
|
||||
editableTextBox.GotFocus += (s, e) => editableTextBox.SelectAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +56,7 @@ namespace Melskin.Controls
|
||||
private void OnEditableTextBoxTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (isInternalOperation) return;
|
||||
|
||||
if (editableTextBox == null) return;
|
||||
string searchText = editableTextBox.Text;
|
||||
string selectedText = GetItemDisplayText(SelectedItem);
|
||||
|
||||
@@ -75,7 +77,7 @@ namespace Melskin.Controls
|
||||
string itemText = GetItemDisplayText(item);
|
||||
|
||||
// 只要包含关键字就显示(忽略大小写)
|
||||
return itemText.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
return itemText.Contains(searchText);
|
||||
};
|
||||
|
||||
// 自动打开下拉框
|
||||
|
||||
Reference in New Issue
Block a user