Skip to content

MultiSelectionSearchComboBox

闫驚鏵(Jinhua Yan) edited this page Jun 26, 2023 · 2 revisions

1)Xaml

DrawingExampleVM DataSource

       <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"
                Columns="2"
                Rows="2">
                <wd:MultiSelectionSearchComboBox
                    Width="200"
                    HorizontalAlignment="Center"
                    VerticalContentAlignment="Center"
                    Delimiter=","
                    DisplayMemberPath="Number"
                    IsSelectAllActive="True"
                    ItemsSource="{Binding Drawings}"
                    SelectedValuePath="Index">
                    <wd:MultiSelectionSearchComboBox.DataContext>
                        <vm:DrawingExampleVM />
                    </wd:MultiSelectionSearchComboBox.DataContext>
                </wd:MultiSelectionSearchComboBox>
                <wd:MultiSelectionSearchComboBox
                    Width="200"
                    HorizontalAlignment="Center"
                    VerticalContentAlignment="Center"
                    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"
                    HorizontalAlignment="Center"
                    VerticalContentAlignment="Center"
                    wd:ElementHelper.Watermark="下拉多选搜索"
                    Delimiter="^"
                    IsSelectAllActive="True"
                    SearchWatermark="请输入搜索内容">
                    <wd:MultiSelectionSearchComboBox.DataContext>
                        <vm:DrawingExampleVM />
                    </wd:MultiSelectionSearchComboBox.DataContext>
                </wd:MultiSelectionSearchComboBox>
            </UniformGrid>
        </Grid>

2)CSharp

       public partial class MultiSelectSearchComboBoxExample : UserControl
    {
        public MultiSelectSearchComboBoxExample()
        {
            InitializeComponent();
            Loaded += MultiSelectSearchComboBoxExample_Loaded;
        }

        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();
        }

        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);      
        }
    }
Clone this wiki locally