本文介绍了我如何列出WPF XAML与色彩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何,我可以得到各种颜色的名单,我可以在Visual Studio设计挑(即 System.Windows.Media.Colors ,但这不是一个集合)并把它们放到我自己的组合框使用WPF和XAML标记?

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?

推荐答案

下面是纯粹XAML解决方案。

Here is the pure XAML solution.

在你的资源节中,你可以使用这个:

In your resources section, you would use this:

<!-- Make sure this namespace is declared so that it's in scope below -->
.. xmlns:sys="clr-namespace:System;assembly=mscorlib" ..

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



或者,作为的时,它可以减少到一个标签

Or, as CodeNaked points out, it can be reduced to one tag:

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

和再组合框是这样的:

<ComboBox Name="comboBox1" 
    ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}"
    DisplayMemberPath="Name"
    SelectedValuePath="Name" />

这篇关于我如何列出WPF XAML与色彩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 01:34