WPF颜色选择器实现 [英] WPF Color Picker Implementation

查看:1782
本文介绍了WPF颜色选择器实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的WPF应用程序创建一个颜色选择器。当我点击任何颜色,该颜色的代码应该进来一个文本框。我用Google搜索了很多,但没有发现任何匹配我的要求。请分享,如果你有这样做过。

I have to create a color picker in my WPF application. When I click on any color, the code of that color should come in a textbox. I googled a lot but found nothing matching my requirement. Please share if you have done like this before.

推荐答案

由于Jodha说,你应该从扩展的WpfToolkit使用拾色器控制。实施拾色器控制很容易,简单地做这样的事情:

As Jodha said, you should use the Color Picker Control from the WpfToolkit Extended. Implementing the Color Picker Control is easy, simply do something like this:

在您的Window对象将这个:

Put this in your Window object:

xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"

和这个地方你希望你的颜色选择器

And this wherever you want your color picker.

<xctk:ColorPicker Name="ClrPcker_Background" SelectedColorChanged="ClrPcker_Background_SelectedColorChanged"></xctk:ColorPicker>



然后,你所要做的就是使用SelectedColorChanged事件改变文本框中的文本,如这样的:

Then, all you have to do is use the SelectedColorChanged event to change the text in the textbox, like this:

private void ClrPcker_Background_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color> e)
{
    TextBox.Text = "#" + ClrPcker_Background.SelectedColor.R.ToString() + ClrPcker_Background.SelectedColor.G.ToString() + ClrPcker_Background.SelectedColor.B.ToString();
}



希望这有助于!

Hope this helps!

这篇关于WPF颜色选择器实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆