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 own ComboBox
using WPF and XAML markup?
views:
2260answers:
3
A:
There is a sample appliation that will be useful for you available to download from MSDN:
ColorPicker Custom Control Sample
This sample shows how to create a custom ColorPicker control and display it in a WPF dialog window.
Peter McGrattan
2009-02-18 20:34:07
I don't need a full featured color picker. I saw that exanple, but it's not what I was looking for.
2009-02-21 18:55:39
+4
A:
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);
Hope this helps!
Ronnie Overby
2009-02-18 20:41:00
+12
A:
Here is the pure XAML solution.
In your resources section, you would use this:
<ObjectDataProvider MethodName="GetType"
ObjectType="{x:Type sys:Type}" x:Key="colorsTypeOdp">
<ObjectDataProvider.MethodParameters>
<sys:String>System.Windows.Media.Colors, PresentationCore,
Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35</sys:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider ObjectInstance="{StaticResource colorsTypeOdp}"
MethodName="GetProperties" x:Key="colorPropertiesOdp">
</ObjectDataProvider>
And then the combobox would look like this:
<ComboBox Name="comboBox1"
ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}"
DisplayMemberPath="Name"
SelectedValuePath="Name" />
casperOne
2009-02-18 21:05:28
This is exactly what I was looking for ;] It works perfectly. Thank you very much for your time and help!
2009-02-21 18:54:45
Go ahead and use your fancy-shmancy declarative programming! See if I care! JK :)
Ronnie Overby
2009-02-24 21:00:45