html5 image combo box,自定义ComboBox控件(美化了combobox控件)

e91b464fe793887612fe6c2b5e395644.png

d588d3bbdad716465786d0466db2ba12.png

资源下载此资源下载价格为3D币,请先登录

资源文件列表

.vs/BeautifyComboBox/v15/.suo , 33792

.vs/BeautifyComboBox/v15/Server/sqlite3/db.lock , 0

.vs/BeautifyComboBox/v15/Server/sqlite3/storage.ide , 4096

.vs/BeautifyComboBox/v15/Server/sqlite3/storage.ide-shm , 32768

.vs/BeautifyComboBox/v15/Server/sqlite3/storage.ide-wal , 638632

Backup/BeautifyComboBox/B_ComboBox.Designer.cs , 1225

Backup/BeautifyComboBox/B_ComboBox.cs , 5826

Backup/BeautifyComboBox/B_ComboBox.resx , 5995

Backup/BeautifyComboBox/BeautifyComboBox.csproj , 4112

Backup/BeautifyComboBox/Form1.Designer.cs , 2641

Backup/BeautifyComboBox/Form1.cs , 403

Backup/BeautifyComboBox/Form1.resx , 5814

Backup/BeautifyComboBox/Program.cs , 534

Backup/BeautifyComboBox/Properties/AssemblyInfo.cs , 1364

Backup/BeautifyComboBox/Properties/Resources.Designer.cs , 2882

Backup/BeautifyComboBox/Properties/Resources.resx , 5612

Backup/BeautifyComboBox/Properties/Settings.Designer.cs , 1101

Backup/BeautifyComboBox/Properties/Settings.settings , 249

Backup/BeautifyComboBox.sln , 938

BeautifyComboBox/B_ComboBox.Designer.cs , 1225

BeautifyComboBox/B_ComboBox.cs , 5787

BeautifyComboBox/B_ComboBox.resx , 5995

BeautifyComboBox/BeautifyComboBox.csproj , 4302

BeautifyComboBox/Form1.Designer.cs , 2641

BeautifyComboBox/Form1.cs , 364

BeautifyComboBox/Form1.resx , 5814

BeautifyComboBox/Program.cs , 534

BeautifyComboBox/Properties/AssemblyInfo.cs , 1364

BeautifyComboBox/Properties/Resources.Designer.cs , 2873

BeautifyComboBox/Properties/Resources.resx , 5612

BeautifyComboBox/Properties/Settings.Designer.cs , 1116

BeautifyComboBox/Properties/Settings.settings , 249

BeautifyComboBox/bin/Debug/BeautifyComboBox.exe , 11264

BeautifyComboBox/bin/Debug/BeautifyComboBox.pdb , 28160

BeautifyComboBox/obj/Debug/BeautifyComboBox.B_ComboBox.resources , 180

BeautifyComboBox/obj/Debug/BeautifyComboBox.Form1.resources , 180

BeautifyComboBox/obj/Debug/BeautifyComboBox.Properties.Resources.resources , 180

BeautifyComboBox/obj/Debug/BeautifyComboBox.csproj.CoreCompileInputs.cache , 42

BeautifyComboBox/obj/Debug/BeautifyComboBox.csproj.FileListAbsolute.txt , 1285

BeautifyComboBox/obj/Debug/BeautifyComboBox.csproj.GenerateResource.cache , 910

BeautifyComboBox/obj/Debug/BeautifyComboBox.csprojAssemblyReference.cache , 9084

BeautifyComboBox/obj/Debug/BeautifyComboBox.exe , 11264

BeautifyComboBox/obj/Debug/BeautifyComboBox.pdb , 28160

BeautifyComboBox/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache , 6985

BeautifyComboBox/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll , 3584

BeautifyComboBox.sln , 1147

BeautifyComboBox.suo , 16384

UpgradeLog.htm , 43900

要实现自定义ComboBox控件,使其能够在点击任何位置都展开,你可以按照以下步骤进行操作: 1. 创建一个自定义控件,继承自ComboBox。 ```csharp public class CustomComboBox : ComboBox { static CustomComboBox() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomComboBox), new FrameworkPropertyMetadata(typeof(CustomComboBox))); } protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { if (!IsDropDownOpen) { IsDropDownOpen = true; e.Handled = true; } else { base.OnPreviewMouseLeftButtonDown(e); } } } ``` 2. 在XAML中,为你的自定义ComboBox控件创建一个新的样式,并将ToggleButton的部分替换为自定义控件中的代码。 ```xaml <Style TargetType="local:CustomComboBox" BasedOn="{StaticResource {x:Type ComboBox}}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:CustomComboBox"> <Grid> <!-- 替换ToggleButton部分 --> <local:CustomComboBoxToggleButton x:Name="ToggleButton" Grid.Column="2" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press" > <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <ContentPresenter x:Name="ContentSite" IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Margin="3,3,23,3" VerticalAlignment="Center" HorizontalAlignment="Left" /> <Path x:Name="DropDownArrow" Grid.Column="1" VerticalAlignment="Center" Margin="0,0,6,0" Data="M0,0 L0,2 L4,6 L8,2 L8,0 L4,4 z" Fill="Black" /> </Grid> </local:CustomComboBoxToggleButton> <!-- 替换Popup部分 --> <Popup x:Name="Popup" AllowsTransparency="True" IsOpen="{TemplateBinding IsDropDownOpen}" PopupAnimation="Slide" Placement="Bottom"> <Grid x:Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}"> <Border x:Name="DropDownBorder" Background="White" BorderThickness="1" BorderBrush="Black" /> <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True"> <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" /> </ScrollViewer> </Grid> </Popup> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> ``` 3. 在你的应用程序中使用自定义ComboBox控件。 ```xaml <local:CustomComboBox Width="200"> <ComboBoxItem>Item 1</ComboBoxItem> <ComboBoxItem>Item 2</ComboBoxItem> <ComboBoxItem>Item 3</ComboBoxItem> </local:CustomComboBox> ``` 通过以上步骤,你可以创建一个自定义ComboBox控件,使其能够在点击任何位置都展开。在自定义控件的样式中,我们重写了PreviewMouseLeftButtonDown事件,并在其中检查IsDropDownOpen属性的状态来决定是否展开ComboBox。这样,无论你点击ComboBox的哪个部分,都能触发展开事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值