使用XAML代码取得.net预定义颜色:
<Page
xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:System.Reflection;assembly=mscorlib"
>
<Page.Resources>
<ObjectDataProvider x:Key=" ColorsProps" ObjectInstance="{x:Type Colors}" MethodName="GetProperties">
<ObjectDataProvider.MethodParameters>
<r:BindingFlags>Public, Static</r:BindingFlags>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<DataTemplate x:Key=" colorTemplate" DataType="{x:Type r:PropertyInfo}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Rectangle Fill="{Binding Name}" Grid.Column="0"
Width="100" Height="24" Margin="2"
HorizontalAlignment="Center"/>
<TextBlock Margin="6,3,3,3" Text="{Binding Name}"
Grid.Column="1" HorizontalAlignment="Center"
FontSize="16"/>
</Grid>
</DataTemplate>
</Page.Resources>
<StackPanel>
<ComboBox ItemsSource="{Binding Source={StaticResource ColorsProps}}"
ItemTemplate="{StaticResource colorTemplate}"
SelectedValuePath="Color"/>
</StackPanel>
</Page>
<Page
xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:System.Reflection;assembly=mscorlib"
>
<Page.Resources>
<ObjectDataProvider x:Key=" ColorsProps" ObjectInstance="{x:Type Colors}" MethodName="GetProperties">
<ObjectDataProvider.MethodParameters>
<r:BindingFlags>Public, Static</r:BindingFlags>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<DataTemplate x:Key=" colorTemplate" DataType="{x:Type r:PropertyInfo}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Rectangle Fill="{Binding Name}" Grid.Column="0"
Width="100" Height="24" Margin="2"
HorizontalAlignment="Center"/>
<TextBlock Margin="6,3,3,3" Text="{Binding Name}"
Grid.Column="1" HorizontalAlignment="Center"
FontSize="16"/>
</Grid>
</DataTemplate>
</Page.Resources>
<StackPanel>
<ComboBox ItemsSource="{Binding Source={StaticResource ColorsProps}}"
ItemTemplate="{StaticResource colorTemplate}"
SelectedValuePath="Color"/>
</StackPanel>
</Page>