内容简介:如何获取可在Visual Studio Designer中选择的所有颜色的列表(这是System.Windows.Media.Colors,但不是集合),并使用WPF和XAML标记将它们放入我自己的ComboBox中?http://stackoverflow.com/questions/562682/how-can-i-list-colors-in-wpf-with-xaml
如何获取可在Visual Studio Designer中选择的所有颜色的列表(这是System.Windows.Media.Colors,但不是集合),并使用WPF和XAML标记将它们放入我自己的ComboBox中?
这是纯XAML解决方案.
在您的资源部分,您将使用:
<!-- 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>
或者,作为 CodeNaked points out ,它可以减少到一个标签:
<ObjectDataProvider
ObjectInstance="{x:Type Colors}"
MethodName="GetProperties"
x:Key="colorPropertiesOdp" />
然后组合框将如下所示:
<ComboBox Name="comboBox1"
ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}"
DisplayMemberPath="Name"
SelectedValuePath="Name" />
http://stackoverflow.com/questions/562682/how-can-i-list-colors-in-wpf-with-xaml
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
CSS 压缩/解压工具
在线压缩/解压 CSS 代码
JSON 在线解析
在线 JSON 格式化工具