Skip to content

Commit

Permalink
Fix issue (#124
Browse files Browse the repository at this point in the history
Fix issue (#124
  • Loading branch information
yanjinhuagood committed Dec 1, 2024
1 parent 3feb946 commit 0f419d4
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,83 @@
<model:HospitalList x:Key="myHospitalList" />
</UserControl.Resources>
<controls:CodeViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Button
Margin="0,20,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Click="Button_Click"
Content="获取选中"
Style="{StaticResource WD.SuccessPrimaryButton}" />
<UniformGrid
Grid.Row="1"
wd:PanelHelper.Spacing="4"
Columns="2"
Rows="2">
<wd:MultiSelectionSearchComboBox
Width="200"
Height="38"
Delimiter=","
DisplayMemberPath="Number"
IsSelectAllActive="True"
ItemsSource="{Binding Drawings}"
SelectedValuePath="Index">
<wd:MultiSelectionSearchComboBox.DataContext>
<vm:DrawingExampleVM />
</wd:MultiSelectionSearchComboBox.DataContext>
</wd:MultiSelectionSearchComboBox>
<wd:MultiSelectionSearchComboBox
Width="200"
wd:ElementHelper.Watermark="MultiSelectionSearchComboBox"
Delimiter="^"
DisplayMemberPath="Number"
IsSelectAllActive="True"
ItemsSource="{Binding Drawings}"
SearchWatermark="请输入搜索内容"
SelectedValuePath="Index">
<wd:MultiSelectionSearchComboBox.DataContext>
<vm:DrawingExampleVM />
</wd:MultiSelectionSearchComboBox.DataContext>
</wd:MultiSelectionSearchComboBox>
<wd:MultiSelectionSearchComboBox
Name="MyMultiSelectionSearchComboBox2"
Width="200"
Height="38"
wd:ElementHelper.Watermark="下拉多选搜索"
Delimiter="^"
IsSelectAllActive="True"
SearchWatermark="请输入搜索内容" />
<wd:MultiSelectionSearchComboBox
Name="MyMultiSelectionSearchComboBox3"
Width="200"
Height="38"
wd:ElementHelper.CornerRadius="3"
Delimiter=","
DisplayMemberPath="Name"
SelectedValuePath="ID" />
</UniformGrid>
</Grid>
<UniformGrid
wd:PanelHelper.Spacing="4"
Columns="2"
Rows="2">
<wd:MultiSelectionSearchComboBox
Width="200"
Height="38"
Delimiter=","
DisplayMemberPath="Number"
IsSelectAllActive="True"
ItemsSource="{Binding Drawings}"
SelectedValuePath="Index">
<wd:MultiSelectionSearchComboBox.DataContext>
<vm:DrawingExampleVM />
</wd:MultiSelectionSearchComboBox.DataContext>
</wd:MultiSelectionSearchComboBox>
<wd:MultiSelectionSearchComboBox
Width="200"
wd:ElementHelper.Watermark="MultiSelectionSearchComboBox"
Delimiter="^"
DisplayMemberPath="Number"
IsSelectAllActive="True"
ItemsSource="{Binding Drawings}"
SearchWatermark="请输入搜索内容"
SelectedValuePath="Index">
<wd:MultiSelectionSearchComboBox.DataContext>
<vm:DrawingExampleVM />
</wd:MultiSelectionSearchComboBox.DataContext>
</wd:MultiSelectionSearchComboBox>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel
HorizontalAlignment="Center"
wd:PanelHelper.Spacing="5"
Orientation="Horizontal">
<Button
Click="Button_Click"
Content="获取选中"
Style="{StaticResource WD.SuccessPrimaryButton}" />
<Button
wd:ElementHelper.CornerRadius="3"
Click="BtnAdd_Click"
Content="Add Item"
Style="{StaticResource WD.SuccessPrimaryButton}" />
</StackPanel>
<StackPanel
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Top"
wd:PanelHelper.Spacing="3"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="Binding:" />
<wd:MultiSelectionSearchComboBox
Name="MyMultiSelectionSearchComboBox2"
wd:ElementHelper.Watermark="下拉多选搜索"
Delimiter="^"
DisplayMemberPath="Name"
IsSelectAllActive="True"
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource AncestorType=local:MultiSelectSearchComboBoxExample}}"
SearchWatermark="请输入搜索内容"
SelectedItems="{Binding SelectedItems, RelativeSource={RelativeSource AncestorType=local:MultiSelectSearchComboBoxExample}}"
SelectedValuePath="ID" />
</StackPanel>
</Grid>

<wd:MultiSelectionSearchComboBox
Name="MyMultiSelectionSearchComboBox3"
Width="200"
Height="38"
wd:ElementHelper.CornerRadius="3"
Delimiter=","
DisplayMemberPath="Name"
SelectedValuePath="ID" />
</UniformGrid>
<controls:CodeViewer.SourceCodes>
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/MultiSelectSearchComboBoxExample.xaml" CodeType="Xaml" />
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/MultiSelectSearchComboBoxExample.xaml.cs" CodeType="CSharp" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ICSharpCode.AvalonEdit.Document;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -11,6 +11,24 @@ namespace WPFDevelopers.Samples.ExampleViews
/// </summary>
public partial class MultiSelectSearchComboBoxExample : UserControl
{
public ObservableCollection<UserInfo> SelectedItems
{
get { return (ObservableCollection<UserInfo>)GetValue(SelectedItemsProperty); }
set { SetValue(SelectedItemsProperty, value); }
}

public static readonly DependencyProperty SelectedItemsProperty =
DependencyProperty.Register("SelectedItems", typeof(ObservableCollection<UserInfo>), typeof(MultiSelectSearchComboBoxExample), new PropertyMetadata(null));

public ObservableCollection<UserInfo> ItemsSource
{
get { return (ObservableCollection<UserInfo>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}

public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(ObservableCollection<UserInfo>), typeof(MultiSelectSearchComboBoxExample), new PropertyMetadata(null));

public MultiSelectSearchComboBoxExample()
{
InitializeComponent();
Expand All @@ -19,11 +37,11 @@ public MultiSelectSearchComboBoxExample()

private void MultiSelectSearchComboBoxExample_Loaded(object sender, RoutedEventArgs e)
{
var list = new List<string>();
for (int i = 0; i < 10; i++)
list.Add(i.ToString());
MyMultiSelectionSearchComboBox2.ItemsSource = list;
MyMultiSelectionSearchComboBox2.SelectedItems = list.Skip(3).ToList();
//var list = new List<string>();
//for (int i = 0; i < 10; i++)
// list.Add(i.ToString());
//MyMultiSelectionSearchComboBox2.ItemsSource = list;
//MyMultiSelectionSearchComboBox2.SelectedItems = list.Skip(3).ToList();

var list2 = new List<UserInfo>();
list2.Add(new UserInfo() { ID = "0", Name = "343DST.com" });
Expand All @@ -32,11 +50,19 @@ private void MultiSelectSearchComboBoxExample_Loaded(object sender, RoutedEventA
list2.Add(new UserInfo() { ID = "3", Name = "josh.peng" });
MyMultiSelectionSearchComboBox3.ItemsSource = list2;
MyMultiSelectionSearchComboBox3.SelectedItems = list2.Where(x => x.ID == "1" || x.ID == "3").ToList();

ItemsSource = new ObservableCollection<UserInfo>(list2);
SelectedItems = new ObservableCollection<UserInfo>(list2.Where(x => x.ID == "1" || x.ID == "3"));
}

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
WPFDevelopers.Controls.MessageBox.Show($"{MyMultiSelectionSearchComboBox2.Text} \r\n总共选中:{MyMultiSelectionSearchComboBox2.SelectedItems.Count} 条","选中内容",MessageBoxButton.OK,MessageBoxImage.Information);
WPFDevelopers.Controls.MessageBox.Show($"{MyMultiSelectionSearchComboBox2.Text} \r\n总共选中:{SelectedItems.Count} 条", "选中内容", MessageBoxButton.OK, MessageBoxImage.Information);
}

private void BtnAdd_Click(object sender, System.Windows.RoutedEventArgs e)
{
ItemsSource.Add(new UserInfo() { ID = "4", Name = "OpenAI.com" });
}
}
public class UserInfo
Expand Down

0 comments on commit 0f419d4

Please sign in to comment.