Skip to content

Commit 29e96ba

Browse files
committed
Fix issue (#124
Fix issue (#124
1 parent d22e92d commit 29e96ba

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/WPFDevelopers.Shared/Controls/MultiSelectionSearchComboBox/MultiSelectSearchComboBox.cs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class MultiSelectionSearchComboBox : Control
7979

8080
public static readonly DependencyProperty SelectedItemsProperty =
8181
DependencyProperty.Register("SelectedItems", typeof(IList), typeof(MultiSelectionSearchComboBox),
82-
new FrameworkPropertyMetadata(null,
82+
new FrameworkPropertyMetadata(new ArrayList(),
8383
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal,
8484
OnSelectedItemsChanged));
8585

@@ -109,37 +109,37 @@ static MultiSelectionSearchComboBox()
109109

110110
public string Delimiter
111111
{
112-
get => (string) GetValue(DelimiterProperty);
112+
get => (string)GetValue(DelimiterProperty);
113113
set => SetValue(DelimiterProperty, value);
114114
}
115115

116116
public string SelectedValuePath
117117
{
118-
get => (string) GetValue(SelectedValuePathProperty);
118+
get => (string)GetValue(SelectedValuePathProperty);
119119
set => SetValue(SelectedValuePathProperty, value);
120120
}
121121

122122
public string DisplayMemberPath
123123
{
124-
get => (string) GetValue(DisplayMemberPathProperty);
124+
get => (string)GetValue(DisplayMemberPathProperty);
125125
set => SetValue(DisplayMemberPathProperty, value);
126126
}
127127

128128
public string Text
129129
{
130-
get => (string) GetValue(TextProperty);
130+
get => (string)GetValue(TextProperty);
131131
set => SetValue(TextProperty, value);
132132
}
133133

134134
public IEnumerable ItemsSource
135135
{
136-
get => (IEnumerable) GetValue(ItemsSourceProperty);
136+
get => (IEnumerable)GetValue(ItemsSourceProperty);
137137
set => SetValue(ItemsSourceProperty, value);
138138
}
139139

140140
public IEnumerable ItemsSourceSearch
141141
{
142-
get => (IEnumerable) GetValue(ItemsSourceSearchProperty);
142+
get => (IEnumerable)GetValue(ItemsSourceSearchProperty);
143143
set => SetValue(ItemsSourceSearchProperty, value);
144144
}
145145

@@ -151,31 +151,31 @@ public object SelectAllContent
151151

152152
public bool IsSelectAllActive
153153
{
154-
get => (bool) GetValue(IsSelectAllActiveProperty);
154+
get => (bool)GetValue(IsSelectAllActiveProperty);
155155
set => SetValue(IsSelectAllActiveProperty, value);
156156
}
157157

158158
public bool IsDropDownOpen
159159
{
160-
get => (bool) GetValue(IsDropDownOpenProperty);
160+
get => (bool)GetValue(IsDropDownOpenProperty);
161161
set => SetValue(IsDropDownOpenProperty, value);
162162
}
163163

164164
public double MaxDropDownHeight
165165
{
166-
get => (double) GetValue(MaxDropDownHeightProperty);
166+
get => (double)GetValue(MaxDropDownHeightProperty);
167167
set => SetValue(MaxDropDownHeightProperty, value);
168168
}
169169

170170
public IList SelectedItems
171171
{
172-
get => (IList) GetValue(SelectedItemsProperty);
172+
get => (IList)GetValue(SelectedItemsProperty);
173173
set => SetValue(SelectedItemsProperty, value);
174174
}
175175

176176
public string SearchWatermark
177177
{
178-
get => (string) GetValue(SearchWatermarkProperty);
178+
get => (string)GetValue(SearchWatermarkProperty);
179179
set => SetValue(SearchWatermarkProperty, value);
180180
}
181181

@@ -236,18 +236,18 @@ public override void OnApplyTemplate()
236236

237237
private void Instance_PropertyChanged(object sender, PropertyChangedEventArgs e)
238238
{
239-
SelectAllContent = LanguageManager.Instance["SelectAll"];
239+
SelectAllContent = LanguageManager.Instance["SelectAll"];
240240
}
241241

242242
private void OnListBoxSearch_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
243243
{
244-
if ((bool) e.NewValue)
244+
if ((bool)e.NewValue)
245245
UpdateIsChecked(_listBoxSearch);
246246
}
247247

248248
private void OnListBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
249249
{
250-
if ((bool) e.NewValue)
250+
if ((bool)e.NewValue)
251251
{
252252
foreach (var item in selectedSearchList)
253253
if (!_listBox.SelectedItems.Contains(item))
@@ -277,7 +277,7 @@ private void UpdateIsChecked(ListBox listBox)
277277

278278
private void OnPopup_GotFocus(object sender, RoutedEventArgs e)
279279
{
280-
var source = (HwndSource) PresentationSource.FromVisual(_popup.Child);
280+
var source = (HwndSource)PresentationSource.FromVisual(_popup.Child);
281281
if (source != null)
282282
{
283283
SetFocus(source.Handle);
@@ -356,7 +356,17 @@ private void OnListBox_SelectionChanged(object sender, SelectionChangedEventArgs
356356
if (e.AddedItems.Count > 0)
357357
SelectionChecked(_listBox);
358358
Combination();
359-
SelectedItems = _listBox.SelectedItems;
359+
var selectedItems = _listBox.SelectedItems;
360+
if (SelectedItems == null)
361+
SelectedItems = selectedItems;
362+
else
363+
{
364+
foreach (var item in selectedItems)
365+
{
366+
if (!SelectedItems.Contains(item))
367+
SelectedItems.Add(item);
368+
}
369+
}
360370
}
361371

362372
private void OnListBoxSearch_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -497,7 +507,7 @@ private static void OnIsDropDownOpenChanged(DependencyObject o, DependencyProper
497507
{
498508
var multiSelectionSearchComboBox = o as MultiSelectionSearchComboBox;
499509
if (multiSelectionSearchComboBox != null)
500-
multiSelectionSearchComboBox.OnIsOpenChanged((bool) e.OldValue, (bool) e.NewValue);
510+
multiSelectionSearchComboBox.OnIsOpenChanged((bool)e.OldValue, (bool)e.NewValue);
501511
}
502512

503513
protected virtual void OnIsOpenChanged(bool oldValue, bool newValue)
@@ -516,7 +526,7 @@ private static void OnMaxDropDownHeightChanged(DependencyObject o, DependencyPro
516526
{
517527
var comboBox = o as MultiSelectionSearchComboBox;
518528
if (comboBox != null)
519-
comboBox.OnMaxDropDownHeightChanged((double) e.OldValue, (double) e.NewValue);
529+
comboBox.OnMaxDropDownHeightChanged((double)e.OldValue, (double)e.NewValue);
520530
}
521531

522532
protected virtual void OnMaxDropDownHeightChanged(double oldValue, double newValue)

0 commit comments

Comments
 (0)