zoukankan      html  css  js  c++  java
  • Silverlight控件学习ComboBox

    在进行开发中有这样一种情况需要ComboBox内集成checkbox列表,或是treeview列表以方便用户进行选择,提供良好的UI体验。

    在开始处理之前先温习下ComboBox的基础东西,就是在XAML中的写法(我用BLEND3拖出的ComboBox控件,冗余代码会多些)

    1、ComboBox控件的基本应用

    代码
     <!--普通combobox测试-->
            
    <ComboBox HorizontalAlignment="Left" Margin="68,53,0,0" VerticalAlignment="Top" Width="120">
                
    <ComboBoxItem Content="测试数据1"/>
                
    <ComboBoxItem Content="测试数据2"/>
            
    </ComboBox>

            
    <!--combobox嵌入rectangle控件-->
            
    <ComboBox Margin="216,53,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120">
                
    <ComboBoxItem>
                    
    <ComboBoxItem.Content>
                        
    <Rectangle Width="200" Height="30" Fill="Blue"/>
                    
    </ComboBoxItem.Content>
                
    </ComboBoxItem>

                
    <ComboBoxItem>
                    
    <ComboBoxItem.Content>
                        
    <Rectangle Width="200" Height="30" Fill="Red"/>
                    
    </ComboBoxItem.Content>
                
    </ComboBoxItem>

                
    <ComboBoxItem>
                    
    <ComboBoxItem.Content>
                        
    <Rectangle Width="200" Height="30" Fill="Green"/>
                    
    </ComboBoxItem.Content>
                
    </ComboBoxItem>
            
    </ComboBox>
            
    <!--combobox嵌入checkbox控件-->
            
    <ComboBox Margin="365,53,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120">
                
    <ComboBoxItem>
                    
    <ComboBoxItem.Content>
                        
    <CheckBox Content="测试数据1"/>
                    
    </ComboBoxItem.Content>
                
    </ComboBoxItem>
                
                
    <ComboBoxItem>
                    
    <ComboBoxItem.Content>
                        
    <CheckBox Content="测试数据2"/>
                    
    </ComboBoxItem.Content>
                
    </ComboBoxItem>
                
                
    <ComboBoxItem>
                    
    <ComboBoxItem.Content>
                        
    <CheckBox Content="测试数据3"/>
                    
    </ComboBoxItem.Content>
                
    </ComboBoxItem>
            
    </ComboBox>

    参考资料:

    Silverlight ComboBox Tutorial

    一步一步学Silverlight 2系列文章

    2、ComboBox集成checkbox列表
    上面的XAML代码中可以看到,我们可以实现将checkbox嵌入comboboxitem的容器中,但这个只能做个测试玩玩,具体应用那是不行的。
    因为在网上已有高手写出了解决办法,不管是从应用角度还是学习角度都不错

    Multiple-Selection ComboBox for Silverlight

     这篇文章中直接对combobox进行了相应的修改,将原来combobox控件中的ItemsPresenter 替换为ListBoxItem ,做法简单,实用


    3、combobox选择后文本框中显示长名称时显示省略号
    看到这个标题不代表我有解决办法,哈哈。在网上找了半天只找到有WPF的相应解决办法。不过各位不要急,有资料说Silverlight 4中增加了TextTriming属性已可以像WPF一样处理 

  • 相关阅读:
    新年快乐,献上一份自己修改的WM6主题。
    做好MSSQL保卫战之xp_cmdshell
    [转载]Validation of viewstate MAC failed异常的原因及解决方法
    数字字符串转换为数字
    理解虚基类、虚函数与纯虚函数的概念
    你的卡销户了吗 - 中国移动收取滞纳金
    解决光驱门打不开的问题
    UCWEB使用之我见
    定时关闭窗口 For Windows Mobile SP/PPC
    减少SQL Server 死锁
  • 原文地址:https://www.cnblogs.com/forrestsun/p/1702253.html
Copyright © 2011-2022 走看看