• ComboBox下拉框项重写


    public partial class SecondPage : Window
        {
            public SecondPage()
            {
                InitializeComponent();
                this.Loaded += this.SecondPage_Loaded;
            }
    
            private void SecondPage_Loaded(object sender, RoutedEventArgs e)
            {
                CustomColorsList colorsList = new CustomColorsList();
                this.cmbColor.ItemsSource = colorsList;
            }
        }
    
        public class CustomContainer : INotifyPropertyChanged
        {
    
            private string _customColors;
    
            public string CustomColors
            {
                get { return _customColors; }
                set { _customColors = value; }
            }
    
            private void Notify(string name)
            {
                if (this.PropertyChanged != null)
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs(name));
                }
            }
            public event PropertyChangedEventHandler PropertyChanged;
        }
    
        public class CustomColorsList : List<CustomContainer>
        {
            public CustomColorsList()
            {
                CustomContainer custom = null;
                Type type = typeof(Brushes);
                var info = type.GetProperties();
                foreach (var property in info)
                {
                    custom = new CustomContainer();
                    custom.CustomColors = property.Name;
                    Add(custom);
                }
            }
        }

    xaml:

    <ComboBox Name="cmbColor" Width="100" Height="30" Margin="77,37,101,194">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Rectangle Fill="{Binding CustomColors}" Width="20" />
                            <TextBlock Text="{Binding CustomColors}" VerticalAlignment="Center" />
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
  • 相关阅读:
    WebPart 生存周期
    【Linq to SharePoint】对列表查询的分页技术
    新闻联播 代码
    首页顶部图片带Flash代码
    [翻译]简单谈谈事件与委托
    asp.net调试
    ASP.NET 2.0加密Web.config 配置文件
    网站用户登录和验证的资料
    Membership的一些资料
    asp.net网站登录的一些资料。
  • 原文地址:https://www.cnblogs.com/kelei12399/p/2608661.html
Copyright © 2020-2023  润新知