WPF 实现多选下拉控件

2023-02-02 10:31:37 +08:00
 yanjinhua

控件名:MultiSelectComboBox

作 者:WPFDevelopersOrg - 驚鏵

原文链接https://github.com/WPFDevelopersOrg/WPFDevelopers

1 ) MultiSelectComboBox.xaml 代码如下: Github|MultiSelectComboBox
码云|MultiSelectComboBox
2 ) MultiSelectComboBoxItem.cs 代码如下:

using System.Windows.Controls;

namespace WPFDevelopers.Controls
{
    public class MultiSelectComboBoxItem : ListBoxItem
    {
    }
}

3 ) MultiSelectComboBox.xaml 代码如下: Github|MultiSelectComboBox.xaml
码云|MultiSelectComboBox.xaml
4 ) MultiSelectComboBoxExample.xaml 代码如下:

<UserControl x:Class="WPFDevelopers.Samples.ExampleViews.MultiSelectComboBoxExample"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews"
             xmlns:wpfdev="https://github.com/WPFDevelopersOrg/WPFDevelopers"
             xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls"
             xmlns:model="clr-namespace:WPFDevelopers.Sample.Models"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <model:HospitalList x:Key="myHospitalList"/>
    </UserControl.Resources>
        <UniformGrid Columns="2">
            <wpfdev:MultiSelectComboBox
                VerticalContentAlignment="Center" 
                HorizontalAlignment="Center"
                Delimiter="^" Width="200">
                <wpfdev:MultiSelectComboBoxItem>Option 1</wpfdev:MultiSelectComboBoxItem>
                <wpfdev:MultiSelectComboBoxItem>Option 2</wpfdev:MultiSelectComboBoxItem>
                <wpfdev:MultiSelectComboBoxItem>Option 3</wpfdev:MultiSelectComboBoxItem>
                <wpfdev:MultiSelectComboBoxItem>Option 4</wpfdev:MultiSelectComboBoxItem>
                <wpfdev:MultiSelectComboBoxItem>Option 5</wpfdev:MultiSelectComboBoxItem>
            </wpfdev:MultiSelectComboBox>
            <wpfdev:MultiSelectComboBox VerticalContentAlignment="Center" 
                                         HorizontalAlignment="Center"
                                         IsSelectAllActive="True"
                             ItemsSource="{Binding Source={StaticResource myHospitalList}}"
                             DisplayMemberPath="DoctorName"
                             SelectedValuePath="ID" Width="200">

            </wpfdev:MultiSelectComboBox>
        </UniformGrid>
        
</UserControl>

1634 次点击
所在节点    .NET
2 条回复
ragnaroks
2023-02-02 11:47:51 +08:00
难能可贵还在坚持 WPF ,现在 dotnet 做图形界面应用程序一般都是 blazor desktop ,MVU (类 react )加点样式表实现这种东西快得很。
yanjinhua
2023-06-02 10:29:56 +08:00
@ragnaroks 是的用 blazor 确实很快、个人就是比较爱好 WPF

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/912483

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX