我不会在我的应用程序ComboBox中使用颜色列表,但我不会将此列表包含在透明颜色中。列表中的附加颜色必须来自Colors类。 我在网上搜索并找到类似的东西:
<ObjectDataProvider MethodName="GetType"
ObjectType="{x:Type System:Type}" x:Key="colorsTypeOdp">
<ObjectDataProvider.MethodParameters>
<System:String>System.Windows.Media.Colors, PresentationCore,
Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35</System:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider ObjectInstance="{StaticResource colorsTypeOdp}"
MethodName="GetProperties" x:Key="colorPropertiesOdp">
</ObjectDataProvider>
<ComboBox Width="80" ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="18" Margin="0,0,0,2">
<Border BorderThickness="1" CornerRadius="2"
BorderBrush="Black" Width="50" VerticalAlignment="Stretch"
Background="{Binding Name}"/>
<TextBlock Text="{Binding Name}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
任何人都知道怎么做这个吗?谢谢你的帮助。
答案 0 :(得分:0)
我建议您从Colors类创建自己的Color
个实例列表,并从此列表中排除Colors.Transparent
颜色。然后,您可以将此列表绑定到组合框的ItemsSource
属性。
要从Color
类获取Colors
个实例的列表,您可以使用以下代码段:
PropertyInfo[] properties = typeof(Colors).GetProperties();
foreach (PropertyInfo property in properties)
Color color = property.GetValue(null, null) as Color;