How can I list colors in WPF with XAML?

前端 未结 4 906
耶瑟儿~
耶瑟儿~ 2020-12-05 08:14

How can I get list of all colors I can pick in Visual Studio Designer (which is System.Windows.Media.Colors, but that isn\'t a collection) and put them into my

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 08:43

    Here is what I have done in a past ASP.net app:

    // populate colors drop down (will work with other kinds of list controls)
    Type colors = typeof(System.Drawing.Color);
    PropertyInfo[] colorInfo = colors.GetProperties(BindingFlags.Public |
        BindingFlags.Static);
    foreach ( PropertyInfo info in colorInfo)
    {
        ddlColor.Items.Add(info.Name);                
    }
    
    // Get the selected color
    System.Drawing.Color selectedColor = 
        System.Drawing.Color.FromName(ddlColor.SelectedValue);
    

提交回复
热议问题