我不想在我的应用程序 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>
有人知道怎么做吗?谢谢你的帮助。