Skip to content

Commit 0f419d4

Browse files
committed
Fix issue (#124
Fix issue (#124
1 parent 3feb946 commit 0f419d4

File tree

2 files changed

+111
-68
lines changed

2 files changed

+111
-68
lines changed

src/WPFDevelopers.Samples.Shared/ExampleViews/MultiSelectSearchComboBoxExample.xaml

+77-60
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,83 @@
1616
<model:HospitalList x:Key="myHospitalList" />
1717
</UserControl.Resources>
1818
<controls:CodeViewer>
19-
<Grid>
20-
<Grid.RowDefinitions>
21-
<RowDefinition Height="Auto" />
22-
<RowDefinition />
23-
</Grid.RowDefinitions>
24-
<Button
25-
Margin="0,20,0,0"
26-
HorizontalAlignment="Center"
27-
VerticalAlignment="Bottom"
28-
Click="Button_Click"
29-
Content="获取选中"
30-
Style="{StaticResource WD.SuccessPrimaryButton}" />
31-
<UniformGrid
32-
Grid.Row="1"
33-
wd:PanelHelper.Spacing="4"
34-
Columns="2"
35-
Rows="2">
36-
<wd:MultiSelectionSearchComboBox
37-
Width="200"
38-
Height="38"
39-
Delimiter=","
40-
DisplayMemberPath="Number"
41-
IsSelectAllActive="True"
42-
ItemsSource="{Binding Drawings}"
43-
SelectedValuePath="Index">
44-
<wd:MultiSelectionSearchComboBox.DataContext>
45-
<vm:DrawingExampleVM />
46-
</wd:MultiSelectionSearchComboBox.DataContext>
47-
</wd:MultiSelectionSearchComboBox>
48-
<wd:MultiSelectionSearchComboBox
49-
Width="200"
50-
wd:ElementHelper.Watermark="MultiSelectionSearchComboBox"
51-
Delimiter="^"
52-
DisplayMemberPath="Number"
53-
IsSelectAllActive="True"
54-
ItemsSource="{Binding Drawings}"
55-
SearchWatermark="请输入搜索内容"
56-
SelectedValuePath="Index">
57-
<wd:MultiSelectionSearchComboBox.DataContext>
58-
<vm:DrawingExampleVM />
59-
</wd:MultiSelectionSearchComboBox.DataContext>
60-
</wd:MultiSelectionSearchComboBox>
61-
<wd:MultiSelectionSearchComboBox
62-
Name="MyMultiSelectionSearchComboBox2"
63-
Width="200"
64-
Height="38"
65-
wd:ElementHelper.Watermark="下拉多选搜索"
66-
Delimiter="^"
67-
IsSelectAllActive="True"
68-
SearchWatermark="请输入搜索内容" />
69-
<wd:MultiSelectionSearchComboBox
70-
Name="MyMultiSelectionSearchComboBox3"
71-
Width="200"
72-
Height="38"
73-
wd:ElementHelper.CornerRadius="3"
74-
Delimiter=","
75-
DisplayMemberPath="Name"
76-
SelectedValuePath="ID" />
77-
</UniformGrid>
78-
</Grid>
19+
<UniformGrid
20+
wd:PanelHelper.Spacing="4"
21+
Columns="2"
22+
Rows="2">
23+
<wd:MultiSelectionSearchComboBox
24+
Width="200"
25+
Height="38"
26+
Delimiter=","
27+
DisplayMemberPath="Number"
28+
IsSelectAllActive="True"
29+
ItemsSource="{Binding Drawings}"
30+
SelectedValuePath="Index">
31+
<wd:MultiSelectionSearchComboBox.DataContext>
32+
<vm:DrawingExampleVM />
33+
</wd:MultiSelectionSearchComboBox.DataContext>
34+
</wd:MultiSelectionSearchComboBox>
35+
<wd:MultiSelectionSearchComboBox
36+
Width="200"
37+
wd:ElementHelper.Watermark="MultiSelectionSearchComboBox"
38+
Delimiter="^"
39+
DisplayMemberPath="Number"
40+
IsSelectAllActive="True"
41+
ItemsSource="{Binding Drawings}"
42+
SearchWatermark="请输入搜索内容"
43+
SelectedValuePath="Index">
44+
<wd:MultiSelectionSearchComboBox.DataContext>
45+
<vm:DrawingExampleVM />
46+
</wd:MultiSelectionSearchComboBox.DataContext>
47+
</wd:MultiSelectionSearchComboBox>
48+
<Grid>
49+
<Grid.RowDefinitions>
50+
<RowDefinition Height="Auto" />
51+
<RowDefinition />
52+
</Grid.RowDefinitions>
53+
<StackPanel
54+
HorizontalAlignment="Center"
55+
wd:PanelHelper.Spacing="5"
56+
Orientation="Horizontal">
57+
<Button
58+
Click="Button_Click"
59+
Content="获取选中"
60+
Style="{StaticResource WD.SuccessPrimaryButton}" />
61+
<Button
62+
wd:ElementHelper.CornerRadius="3"
63+
Click="BtnAdd_Click"
64+
Content="Add Item"
65+
Style="{StaticResource WD.SuccessPrimaryButton}" />
66+
</StackPanel>
67+
<StackPanel
68+
Grid.Row="1"
69+
HorizontalAlignment="Center"
70+
VerticalAlignment="Top"
71+
wd:PanelHelper.Spacing="3"
72+
Orientation="Horizontal">
73+
<TextBlock VerticalAlignment="Center" Text="Binding:" />
74+
<wd:MultiSelectionSearchComboBox
75+
Name="MyMultiSelectionSearchComboBox2"
76+
wd:ElementHelper.Watermark="下拉多选搜索"
77+
Delimiter="^"
78+
DisplayMemberPath="Name"
79+
IsSelectAllActive="True"
80+
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource AncestorType=local:MultiSelectSearchComboBoxExample}}"
81+
SearchWatermark="请输入搜索内容"
82+
SelectedItems="{Binding SelectedItems, RelativeSource={RelativeSource AncestorType=local:MultiSelectSearchComboBoxExample}}"
83+
SelectedValuePath="ID" />
84+
</StackPanel>
85+
</Grid>
86+
87+
<wd:MultiSelectionSearchComboBox
88+
Name="MyMultiSelectionSearchComboBox3"
89+
Width="200"
90+
Height="38"
91+
wd:ElementHelper.CornerRadius="3"
92+
Delimiter=","
93+
DisplayMemberPath="Name"
94+
SelectedValuePath="ID" />
95+
</UniformGrid>
7996
<controls:CodeViewer.SourceCodes>
8097
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/MultiSelectSearchComboBoxExample.xaml" CodeType="Xaml" />
8198
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/MultiSelectSearchComboBoxExample.xaml.cs" CodeType="CSharp" />

src/WPFDevelopers.Samples.Shared/ExampleViews/MultiSelectSearchComboBoxExample.xaml.cs

+34-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using ICSharpCode.AvalonEdit.Document;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
33
using System.Linq;
44
using System.Windows;
55
using System.Windows.Controls;
@@ -11,6 +11,24 @@ namespace WPFDevelopers.Samples.ExampleViews
1111
/// </summary>
1212
public partial class MultiSelectSearchComboBoxExample : UserControl
1313
{
14+
public ObservableCollection<UserInfo> SelectedItems
15+
{
16+
get { return (ObservableCollection<UserInfo>)GetValue(SelectedItemsProperty); }
17+
set { SetValue(SelectedItemsProperty, value); }
18+
}
19+
20+
public static readonly DependencyProperty SelectedItemsProperty =
21+
DependencyProperty.Register("SelectedItems", typeof(ObservableCollection<UserInfo>), typeof(MultiSelectSearchComboBoxExample), new PropertyMetadata(null));
22+
23+
public ObservableCollection<UserInfo> ItemsSource
24+
{
25+
get { return (ObservableCollection<UserInfo>)GetValue(ItemsSourceProperty); }
26+
set { SetValue(ItemsSourceProperty, value); }
27+
}
28+
29+
public static readonly DependencyProperty ItemsSourceProperty =
30+
DependencyProperty.Register("ItemsSource", typeof(ObservableCollection<UserInfo>), typeof(MultiSelectSearchComboBoxExample), new PropertyMetadata(null));
31+
1432
public MultiSelectSearchComboBoxExample()
1533
{
1634
InitializeComponent();
@@ -19,11 +37,11 @@ public MultiSelectSearchComboBoxExample()
1937

2038
private void MultiSelectSearchComboBoxExample_Loaded(object sender, RoutedEventArgs e)
2139
{
22-
var list = new List<string>();
23-
for (int i = 0; i < 10; i++)
24-
list.Add(i.ToString());
25-
MyMultiSelectionSearchComboBox2.ItemsSource = list;
26-
MyMultiSelectionSearchComboBox2.SelectedItems = list.Skip(3).ToList();
40+
//var list = new List<string>();
41+
//for (int i = 0; i < 10; i++)
42+
// list.Add(i.ToString());
43+
//MyMultiSelectionSearchComboBox2.ItemsSource = list;
44+
//MyMultiSelectionSearchComboBox2.SelectedItems = list.Skip(3).ToList();
2745

2846
var list2 = new List<UserInfo>();
2947
list2.Add(new UserInfo() { ID = "0", Name = "343DST.com" });
@@ -32,11 +50,19 @@ private void MultiSelectSearchComboBoxExample_Loaded(object sender, RoutedEventA
3250
list2.Add(new UserInfo() { ID = "3", Name = "josh.peng" });
3351
MyMultiSelectionSearchComboBox3.ItemsSource = list2;
3452
MyMultiSelectionSearchComboBox3.SelectedItems = list2.Where(x => x.ID == "1" || x.ID == "3").ToList();
53+
54+
ItemsSource = new ObservableCollection<UserInfo>(list2);
55+
SelectedItems = new ObservableCollection<UserInfo>(list2.Where(x => x.ID == "1" || x.ID == "3"));
3556
}
3657

3758
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
3859
{
39-
WPFDevelopers.Controls.MessageBox.Show($"{MyMultiSelectionSearchComboBox2.Text} \r\n总共选中:{MyMultiSelectionSearchComboBox2.SelectedItems.Count} 条","选中内容",MessageBoxButton.OK,MessageBoxImage.Information);
60+
WPFDevelopers.Controls.MessageBox.Show($"{MyMultiSelectionSearchComboBox2.Text} \r\n总共选中:{SelectedItems.Count} 条", "选中内容", MessageBoxButton.OK, MessageBoxImage.Information);
61+
}
62+
63+
private void BtnAdd_Click(object sender, System.Windows.RoutedEventArgs e)
64+
{
65+
ItemsSource.Add(new UserInfo() { ID = "4", Name = "OpenAI.com" });
4066
}
4167
}
4268
public class UserInfo

0 commit comments

Comments
 (0)