WPF ComboBox 颜色选择器

来源:互联网 发布:数据分析师发展 编辑:程序博客网 时间:2024/05/21 09:49

在stackoverflow看到一篇关于颜色选择的代码,感觉挺好,所以借鉴过来与大家分享下。

代码如下:

<ObjectDataProvider             ObjectInstance="{x:Type Colors}"             MethodName="GetProperties"             x:Key="colorPropertiesOdp" />

<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>

<ComboBox Name="comboBox1"                     ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}"                     >                <ComboBox.ItemTemplate>                    <DataTemplate>                        <StackPanel Orientation="Horizontal">                            <Rectangle Fill="{Binding Name}" Width="40" Height="10"></Rectangle>                            <TextBlock Text="{Binding Name}"></TextBlock>                        </StackPanel>                    </DataTemplate>                </ComboBox.ItemTemplate>            </ComboBox>
上面两个资源都可用,可任选一个。

0 0