silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight 中 ComboBox+TreeView 实现的下拉控件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_674_0@
@H_197_3@概述 性能描述:   ComboBox+TreeView实现的用户控件,设置数据源后,可以递归加载数据,支持双向绑定   控件截图:        XAML界面设计: <UserControl x:Class="ChuanyeOA.Customcatontrols.ComboBoxTree"     xmlns="http://scheR_545_11845@as.microsoft.com/winfx/2006/xaml/pr

@L_618_0@描述:

  ComboBox+TreeView实现的用户控件,设置数据源后,可以递归加载数据,支持双向绑定

  控件截图:

  

Silverlight 中 ComboBox+TreeView 实现的下拉控件

 

  XAML界面设计:

<UserControl x:Class="ChuanyeOA.Customcatontrols.ComboBoxTree"
    xmlns=
"http://scheR_545_11845@as.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x=
"http://scheR_545_11845@as.microsoft.com/winfx/2006/xaml"
    xmlns:d=
"http://scheR_545_11845@as.microsoft.com/expression/blend/2008"
    xmlns:mc=
"http://scheR_545_11845@as.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable=
"d"
    d:DesignHeight=
"30" d:DesignWidth="300" xmlns:sdk="http://scheR_545_11845@as.microsoft.com/winfx/2006/xaml/presentation/sdk">
    
    <Grid x:Name="LayoutRoot">
        <ComboBox Height="23" NAME="cbMain" HorizontalAlignment="Stretch" VerticalAlignment= DropDownOpened="cbMain_DropDownOpened" DropDownClosed="cbMain_DropDownClosed">
            <ComboBoxItem x:Name="cbItemTreeView">
                <ComboBoxItem.Content>
                    <sdk:TreeView NAME="tvList" SELEctedItemChanged="tvList_SELEctedItemChanged" />
                </ComboBoxItem.Content>
            </ComboBoxItem>

            <"cbItemDisplay" >
            </ComboBoxItem>
        </ComboBox>
    </Grid>
</UserControl>

  后台CS代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Windows.Data;

using System.Collections;
using System.Reflection;

/********************************
 * 创建人:刘跃飞
 * 创建时间:2010-09-21
 * 功能描述:ComboBox+TreeView实现的用户控件,主要实现选择TreeView中的项做为ComboBox的项的功能
 * 属性描述:此控件包含以下几个属性
 * 1.Itemssource:控件要绑定的数据源
 * 2.SELEctedValuePath:选中的值的属性
 * 3.DisplaymemberPath:获取或设置为每个数据项要显示属性名称
 * 4.SELEctedItem  当前选择的项
 * 5.SELEctedValue  当前选择的值
 * 6.IsRecursionEnabled 设置是否启用递归加载数据源中的项 。需要设置ChildName和ParentName两个属性
 * 7.ChildMemberPath 递归加载数据源时,实体中的子级属性
 * 8. ParentMemberPath 递归加载数据源时,实体中的父级属性
 * 9.IsExpandAll 设置TreeView打开时是全部打开状态还是收缩状态 认为True打开状态
 * 
 * 使用方法
 * 注意事项:本控件设计尚不完善,【Itemssource】属性需要在最后设置,否则,将提示错误
 * 1.界面上直接设置,例如:
 *  <myControl:ComboBoxTree SELEctedValue="{Binding DepartmentID, Mode=TwoWay}" DisplaymemberPath="DepartName" SELEctedValuePath="ID" IsRecursionEnabled="True" ChildMemberPath="ID" ParentMemberPath="ParentID"  Itemssource="{Binding Data, source={Staticresource a_DepartmentDomainDatasourcE}}">
 * 2.在后台代码中直接设置,例如:
 *           comboBoxTree1.DisplaymemberPath = "Name";
 *           comboBoxTree1.SELEctedValuePath = "ID";
 *           comboBoxTree1.ChildMemberPath = "ID";
 *           comboBoxTree1.ParentMemberPath = "ParentID";
 *           comboBoxTree1.IsRecursionEnabled = true;
 *           comboBoxTree1.Itemsource = MyControls.DepartmenTinfo.GetDepartment().AsEnumerable();
 * 3.如果启用递归加载,父级ID为【0】的项,将作为根节点加载,如果没有父级ID为【0】的项,将无法进行加载
 * 4.此控件用到了TreeView的ExpandAll扩展方法,需要添加【System.Windows.Controls.Toolkit】类库的引用,否则将提示找不到此方法
 * ***********************************/


namespace ChuanyeOA.Customcatontrols
{
    public partial class ComboBoxTree : UserControl
    {      
        public ComboBoxTree()
        {
            initializeComponent();

            this.Layoutupdated += new EventHandler(ComboBoxTree_Layoutupdated);
        }

        void ComboBoxTree_Layoutupdated(object sender, EventArgs E)
        {
            if (this.IsExpandAll)
            {
                //--展开所有节点
                tvList.ExpandAll();
            }
        }

        #region Itemsource 设置或获得绑定的数据源(属性
        
        public static readonly DependencyProperty ItemssourceProperty =
            DependencyProperty.Register("Itemssource"typeof(IEnumerablE),255)">typeof(ComboBoxTreE),255)">new PropertyMetadata(new PropertyChangedCallBACk(ItemssourcePropertyChangedCallBACk)));
        /// <sumMary>
        /// 数据源
        /// </sumMary>
        public IEnumerable Itemssource
        {
            get
            {
                return (IEnumerablE)this.GetValue(ItemssourceProperty);
            }
            set
            {
                this.SETVALue(ItemssourceProperty,255)">value);
            }
        }
        //--属性更改的回调事件
        void ItemssourcePropertyChangedCallBACk(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            if (sender != null)
            {
                ComboBoxTree comboBoxTree = sender as ComboBoxTree;

                if (comboBoxTree.IsRecursionEnabled == false)
                {
                    // 以列表的方式加载数据
                    comboBoxTree.LoadTreeViewDataWithList();
                }
                else
                {
                    //以递归的方式加载数据                     comboBoxTree.LoadTreeViewDataWithRecursion();                 }             }         }

大佬总结

以上是大佬教程为你收集整理的Silverlight 中 ComboBox+TreeView 实现的下拉控件全部内容,希望文章能够帮你解决Silverlight 中 ComboBox+TreeView 实现的下拉控件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。