zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    JS事件
    BOM
    DOM
    常见的SQL字符串函数
    常用的认证方式
    后台代码扫描规则-sonarQube官方
    spring cloud中feign的使用
    常见基于 REST API 认证方式
    Java中连接池
    这是一张心情贴
  • 原文地址:https://www.cnblogs.com/kelei12399/p/2608661.html
Copyright © 2011-2022 走看看