将颜色加载到comboBox [英] Load colors into comboBox
问题描述
我正在制作一个自制的文本编辑器,并在其中尝试制作一个用于更改文本颜色的控件,在我的工具栏上有一个组合框,希望将系统颜色加载到其中,以便用户可以更改所选文本的颜色。我无法弄清楚如何用这些颜色填充组合框,我尝试了在page_loaded事件中在互联网上发现的各种变化,但似乎无法使其正常工作。希望您能提供帮助
I am making a homemade text editor and in it trying to make a control used to change the color of the text, on my tool bar I have a combo box in which I want to be able to load system colors into so that the user may change the color of the selected text. I can not figure out how to populate the combo box with these colors, I have tried variation of things I have found on the internet within my page_loaded event, but can not seem to get it to work. Hope you can help
谢谢牛肉
推荐答案
您可以使用此功能代码以用所有颜色的列表填充组合框
You can use this code to populate a combo box with list of all colors
声明资源
<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>
然后在组合框中使用该资源
Then use that resource in combo box like this
<ComboBox Name="comboBox1" ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}" DisplayMemberPath="Name" SelectedValuePath="Name" />
为了使用 sys:string
将必须包含
xmlns:sys = clr-namespace:System; assembly = mscorlib
这篇关于将颜色加载到comboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!