WPF 自定义下拉列表

XAML代码:

<Popup x:Name="popupStrategy" StaysOpen="False" PopupAnimation="Scroll" Width="190" MaxHeight="300" AllowsTransparency="True">
    <Border Background="#0c5ab0" BorderThickness="1" BorderBrush="#1992d6">
        <ItemsControl x:Name="itemsCtrlStrategy" Grid.Row="1" Margin="0 5 0 0">
            <ItemsControl.Template>
                <ControlTemplate>
                    <ScrollViewer HorizontalScrollBarVisibility="Auto" MinHeight="{Binding ElementName=itemsCtrlStrategy,Path=ActualHeight}" MinWidth="{Binding ElementName=itemsCtrlStrategy, Path=ActualWidth}">
                        <ItemsPresenter></ItemsPresenter>
                    </ScrollViewer>
                </ControlTemplate>
            </ItemsControl.Template>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="5 0 5 5" Background="#00234E">
                        <Button x:Name="btnStrategySel" Click="btnStrategySel_Click_1" CommandParameter="{Binding}" Width="120" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center">
                            <Button.Template>
                                <ControlTemplate>
                                    <TextBlock Text="{Binding Info.STRATEGYNAME}" ToolTip="{Binding Info.STRATEGYNAME}" Width="120" Foreground="#1ba4f6" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                        <Button x:Name="btnStrategyDel" Margin="5" CommandParameter="{Binding}" Click="btnStrategyDel_Click_1" Height="12" Width="12" VerticalAlignment="Center" HorizontalAlignment="Center">
                            <Button.Template>
                                <ControlTemplate>
                                    <Image Name="img" Width="12" Height="12" VerticalAlignment="Center" Source="/SunCreate.CombatPlatform.Client.Resources;component/Image/CaseExportStrategy/删除.png"></Image>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                        <Button x:Name="btnStrategyEdit" Margin="5" CommandParameter="{Binding}" Click="btnStrategyEdit_Click_1" Height="12" Width="12" VerticalAlignment="Center" HorizontalAlignment="Center">
                            <Button.Template>
                                <ControlTemplate>
                                    <Image Name="img" Width="12" Height="12" VerticalAlignment="Center" Source="/SunCreate.CombatPlatform.Client.Resources;component/Image/CaseExportStrategy/编辑.png"></Image>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Border>
</Popup>

后台代码:

itemsCtrlStrategy.ItemsSource = strategyViewModelList;

popupStrategy.PlacementTarget = sender as Button;
popupStrategy.Placement = PlacementMode.Bottom;
popupStrategy.IsOpen = true;

效果图:

原文地址:https://www.cnblogs.com/s0611163/p/8759016.html

时间: 2024-08-15 23:23:18

WPF 自定义下拉列表的相关文章

WPF自定义样式篇-DataGrid

WPF自定义样式篇-DataGrid 先上效果图: 样式: <!--DataGrid样式-->    <Style TargetType="DataGrid">        <Setter Property="RowHeaderWidth" Value="0"></Setter>        <Setter Property="AutoGenerateColumns"

WPF自定义路由事件

一 概要 本文通过实例演示WPF自定义路由事件的使用,进而探讨了路由事件与普通的CLR事件的区别(注:"普通的CLR事件"这个说法可能不太专业,但是,我暂时也找不到什么更好的称呼,就这么着吧,呵呵.)(扩展阅读:例说.NET事件的使用). 二 实例演示与说明 1 新建DetailReportEventArgs类,该类派生自RoutedEventArgs类,RoutedEventArgs类包含与路由事件相关的状态信息和事件数据.DetailReportEventArgs类中定义了属性Ev

WPF 自定义柱状图 BarChart

WPF 自定义柱状图 1. <UserControl x:Class="WpfApplication11.BarChartControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.o

WPF自定义窗口基类

WPF自定义窗口基类时,窗口基类只定义.cs文件,xaml文件不定义.继承自定义窗口的类xaml文件的根节点就不再是<Window>,而是自定义窗口类名(若自定义窗口与继承者不在同一个命名空间,还得加上命名空间),继承自定义窗口类后台代码也得修改为继承自自定义窗口exp: //继承Window类的自定义窗口类 namespace WPF_Study.Entity { using System.Windows; public class WindowBase:Window { private c

WPF自定义路由事件(二)

WPF中的路由事件 as U know,和以前Windows消息事件区别不再多讲,这篇博文中,将首先回顾下WPF内置的路由事件的用法,然后在此基础上自定义一个路由事件. 1.WPF内置路由事件 WPF中的大多数事件都是路由事件,WPF有3中路由策略: 具体不多讲,单需要注意的是WPF路由事件是沿着VIsualTree传递的.VisualTree与LogicalTree的区别在于:LogicalTree的叶子节点是构成用户界面的控件(xaml紧密相关),而VisualTree要连控件中的细微结构也

自定义下拉列表控件

问题及需求 输入汉字或全拼或简拼均可得到结果(此需求用原生的ComboBox不容易实现) 点击文本框时弹出下拉列表 进入文本框时弹出下拉列表 输入文字时,如果有结果,则弹出下拉列表 除文本框和下拉列表外,点击任何地方均隐藏下拉列表 单击下拉列表中的文字,文本出现在文本框,关闭下拉列表 下拉列表出现后,默认选中第一项,第一项高亮 回车后下拉列表中选中的文本出现在文本框中 2.解决思路 用Panel作为容器,装载ListView,作为下拉列表的数据容器 定义下拉列表显示方法,并使用+=将其添加到文本

WPF:自定义Metro样式文件夹选择对话框FolderBrowserDialog

1.前言 WPF并没有文件选择对话框,要用也就只有使用Winform版的控件.至今我也没有寻找到一个WPF版本的文件选择对话框. 可能是我眼浊,如果各位知道有功能比较健全的WPF版文件选择对话框.文件打开对话框,还请留言告知. 这次做的是一个精简版的文件选择对话框.包含一个UserControl和一个承载UserControl的Window. 另外TreeView的样式引用自Mahspps中的样式.也就是如果需要使用这个文件选择对话框,就必须要引用Mahapps的相关dll. 当然,我会提供整个

ARCGIS自定义下拉列表

1  创建一个geodatabase数据库 2 点击属性--->Domain-->>输入名称,在下面的属性设置中选择coded value 3  在下面的列表中输入下拉列表中可供选择的值,例如 1  通达   2 通乡  3  其他等等. 4 打开要素类的属性,在Fields下选择要给哪个字段提供下拉列表,并且这个字段的类型必须和你所建立的domain的类型是相同的,然后在该字段的domain下选择刚刚建立的domain名即可. 5 在ArcMap中打开该文件的属性表,在设置了下拉列表的

WPF 自定义滚动条样式

先看一下效果: 先分析一下滚动条有哪儿几部分组成: 滚动条总共有五部分组成: 两端的箭头按钮,实际类型为RepeatButton Thumb 两端的空白,实际也是RepeatButton 最后就是Thumb(滑块) 所以如果要修改滚动条的样式,就要修改这五部分的样式.具体代码如下: <!--自定义滚动条样式-->            <SolidColorBrush x:Key="StandardBorderBrush"