多级下拉菜单zz

MultiLevelMultiSelectCombo (Silverlight)

Tharindu Nishad Patikirikorala, 14 Aug 2013 CPOL

5.00 (1 vote)

Rate:

vote 1vote 2vote 3vote 4vote 5

The MultiLevelMultiSelectCombo is an extension of the Silverlight combo box having capabilities to display hierarchical data and enable selection of multiple items.

Is your email address OK? You are signed up for our newsletters but your email address is either unconfirmed, or has not been reconfirmed in a long time. Please click here to have a confirmation email sent so we can confirm your email address and start sending you newsletters again. Alternatively, you can update your subscriptions.

Introduction

The default combo box control that comes with Silverlight enables us to show a single level and there is no way to select multiple items from that list. This article presents a ComboBox control that can be used to display a set of selections based on hierarchal data and select multiple items from it, hence called asMultiLevelMultiSelectCombo.

Features and Settings

Let us look at the features of MultiLevelMultiSelectCombo.

  • Multilevel mode: the multiple selection capability with multiple levels.
  • SelectAll mode: the multiple selection capability with multiple levels including select all option.
  • Image mode: the multiple selection capability with multiple levels including images for each item.
  • Enum mode: given an enum type, displays multi selection capabilities. 

Implementation 

This is a control designed to enable multiple selections, but still operate as a combo box control. In this implementation, the user control is designed with a combination of a combo box having aComboBox.ItemTemplate of the tree view. Tree view is suitable to display hierarchical data. AHierarchicalDataTemplate is used to display the required data and check boxes are used to enable the selection of multiple items form that hierarchy as follows: 

Collapse | Copy Code

<sdk:hierarchicaldatatemplate x:key="TreeViewTemplate" itemssource="{Binding Path=ChildItemList}">
        <grid horizontalalignment="Stretch">
            <grid.columndefinitions>
                <columndefinition width="Auto">
                <columndefinition width="Auto">
                <columndefinition width="Auto">
            </columndefinition></columndefinition>
            </columndefinition></grid.columndefinitions>

            <checkbox grid.column="1" horizontalcontentalignment="Stretch"
                      ischecked="{Binding IsChecked, Mode=TwoWay}"
                      verticalalignment="Center" margin="3,0,0,0">
                <stackpanel orientation="Horizontal">
                <img source="{Binding Image}"
                  horizontalalignment="Center" margin="0" />
                <textblock horizontalalignment="Stretch"
                  text="{Binding Display}" margin="3,0,0,0"
                  verticalalignment="Center">
                </textblock></stackpanel>
            </checkbox>
        </grid>
    </sdk:hierarchicaldatatemplate>

<combobox height="25" name="ItemListCombo">
    <combobox.itemcontainerstyle>
        <style targettype="ComboBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </style>
    </combobox.itemcontainerstyle>
    <combobox.itemtemplate>
        <datatemplate>
            <sdk:treeview itemssource="{Binding Path=Tag,ElementName=ItemListCombo}"
               itemtemplate="{StaticResource TreeViewTemplate}"
               horizontalalignment="Stretch" horizontalcontentalignment="Stretch">
        </sdk:treeview></datatemplate>
    </combobox.itemtemplate>
</combobox>

Note that the combo box data source only has one item, which becomes the source to the tree view in that item.

Now, in order to expose custom properties for this control such as hierarchical data list and other configuration properties, DependencyProperties have been declared for each.

Collapse | Copy Code

public static readonly DependencyProperty ItemListProperty = DependencyProperty.Register("ItemList",
     typeof(List<MultiSelectComboItem>), typeof(MultiLevelMultiSelectComboBox),
     new PropertyMetadata((s, e) => ((MultiLevelMultiSelectComboBox)s).SetItemsSource()));

public List<MultiSelectComboItem> ItemList
{
    get { return (List<MultiSelectComboItem>)GetValue(ItemListProperty); }
    set { SetValue(ItemListProperty, value); }
}

Among the properties are:

  • ItemList: This is the desired hierarchical data to be displayed. Each item of this list should be of typeMultiSelectComboItem. It is important to note that when an item is checked, to trigger selections up and down the hierarchy, the Parent and ChildItemList properties have to be assigned properly in eachMultiSelectComboItem included in the ItemList. At the top most level, leave Parent as null and at the lowest level, leave the ItemList as null (see the sample project). 

    In the case of binding Enums, the user does not have to prepare a MultiSelectComboItem list. Instead, the EnumToMultiItemListConverter can be used as follows, which will convert an Enum to a MultiSelectComboItem list as follows. EnumCountry is an Enum Country exposed as a binding property in the DataContext. 

    Collapse | Copy Code

    ItemList="{Binding Path=EnumCountry, Converter={StaticResource EnumToMultiItemListConverter}}"  
  • SetSelectAll: If true, this property includes the Select All item in the list.
  • SelectedList: Returns the MultiSelectComboItem list with the selected items and their hierarchy. Use a LINQ query to list all selected items at different levels.

Use Cases

In this section, a XAML code snippet is presented in order to explain how to use this control.

Collapse | Copy Code

 xmlns:control="clr-namespace:MultiLevelMultiSelectCombo"
<control:MultiLevelMultiSelectComboBox SelectedItemList="{Binding SelectedList, Mode=TwoWay}"
  ItemList="{Binding Path=ComboAreaList,Mode=OneTime}"
  Width="400" SetSelectAll="True"/>

 

 

http://www.codeproject.com/Tips/612864/MultiLevelMultiSelectCombo-Silverlight

时间: 2024-08-11 02:55:46

多级下拉菜单zz的相关文章

DroDownList控件多级下拉菜单

后台代码: /// <summary> /// 绑定下拉菜单 /// </summary> private void BindDropList() { DataTable dt = bacManage.GetAllArticleCategory(); CreateLevelDropDown(drpCategoryId, dt); } /// <summary> /// 创建分级下拉框 /// </summary> /// <param name=&qu

jQuery制作水平多级下拉菜单

本篇体验使用jQuery制作水平的.多级的.下拉菜单. 下拉菜单的html部分如下. <body> <nav class="main-nav"> <ul class="nav-list"> <li><a href="#">主页</a></li> <li><a href="#">产品</a></li>

基于jQuery带图标的多级下拉菜单

之前为大家分享了很多导航菜单.今天我们要来分享一款很不错的jQuery左侧带小图标的多级下拉菜单,菜单是垂直的,每一个菜单项带有一个小图标,看起来非常专业.并且菜单支持无限极下拉,所以对各位Web开发者来说非常实用.菜单时基于jQuery的,所以基本可以支持所有的浏览器. 在线预览   源码下载 实现的代码. html代码: <div class="content"> <ul class="vertical-nav dark red"> &l

Bootstrap 3 &amp; 4 的多级下拉菜单示例

Bootstrap 虽好,但对于复杂的界面,还是有N多组件需要自己扩展,并且要往简洁.大气的Bootstrap界面上靠,着实要费一些功夫.下面分享一个Bootstrap 3的多级下拉菜单,无需第三方Js脚本,复制后直接可用. Bootstrap 3 的多级下拉菜单示例 <!DOCTYPE HTML> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title&

js控制的多级下拉菜单

最近身体不适,所以没能如期的更新,抱歉.这里直接把代码贴上,如果有不明白的地方,留言就行. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> &

jquery多级下拉菜单

var menu = new Click('#menu',{target:'p',parent:'li',contr:'ul',way:0}); /* 参数说明: target : 点击事件发生在该元素内 way : 0 只显示一个,1点击即显示; parent : 点击的祖先元素标识,用以查找控制元素 contr : 控制的元素 */function Click(me,parm){ var tar = parm.target, parent = parm.parent, contr = par

bootstrap 多级下拉菜单

如上效果: 实现代码: 导入js和css: 1 <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> 2 <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></scri

下拉菜单之纯CSS实现

最近对一批学员进行网页培训,应他们要求,将这些课堂知识整理出来,供他们参考和回忆.当然,小寻哥是不愿意这么做的,毕竟白天培训+写项目,没有时间整理(当然是意味晚上整理啦).哎,但是架不住前端美女的要求,答应了就只能照办了. 这里也给其他刚入门的小虾们头参考下吧.(部分整理,毕竟有些机密还是不能外泄的) 直接上代码,你们运行下吧 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w

css+html+js实现多级下拉和弹出菜单

本文将使用css+html+js实现横向菜单.具有多级弹出菜单下拉. 首先我们来看看效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvajkwMzgyOTE4Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" > 首先应该写html部分的代码,代码比較简单,代码例如以下: <body> <div id="men