开发者

Load colors into comboBox

开发者 https://www.devze.com 2023-03-22 20:59 出处:网络
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 t

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

Thanks Beef


You can use this code to populate a combo box with list of all colors

Declare a resource

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

In order to use sys:string you will have to include xmlns:sys="clr-namespace:System;assembly=mscorlib"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号