新的扩展WPFToolkit ColorPicker

Jef*_*ain 6 wpf controls

我一直试图从我的应用程序中的工具包中获取新的颜色选择器,但没有成功......

以下是应该采用窗口背景颜色来填充当前颜色的示例代码,并且在新选择时,应该将背景颜色更改为所选颜色...

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="100" Width="200" xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended" 
        Name="Window" Background="blue">
    <Grid>
        <extToolkit:ColorPicker Name="colorPicker1" 
                                SelectedColor="{Binding ElementName=Window,Path=Background}" 
                                CurrentColor="{Binding ElementName=Window,Path=Background}" />
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

这是我在彩色标签上找到的所有文档...... http://elegantcode.com/2010/08/15/extended-wpf-toolkit-new-colorpicker-control/

Fre*_*lad 9

这里的问题是Window.Background是Brush和SelectedColor,CurrentColor是Color.您可以使用转换器来实现此功能.

<Window x:Class="WpfApplication1.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
        xmlns:local="clr-namespace:WpfApplication1"
        Title="MainWindow" Height="100" Width="200"   
        Name="Window" Background="blue">
    <Window.Resources>
        <local:BrushColorConverter x:Key="BrushColorConverter"/>
    </Window.Resources>
    <Grid>
        <extToolkit:ColorPicker Name="colorPicker1"  
                                SelectedColor="{Binding ElementName=Window, 
                                    Path=Background, 
                                    Converter={StaticResource BrushColorConverter}}"
                                CurrentColor="{Binding ElementName=Window, 
                                    Path=Background, 
                                    Converter={StaticResource BrushColorConverter}}" />
    </Grid>
</Window> 
Run Code Online (Sandbox Code Playgroud)

和转换器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;

namespace WpfApplication1
{
    public class BrushColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            SolidColorBrush brush = value as SolidColorBrush;
            return brush.Color;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Color color = (Color)value;
            return new SolidColorBrush(color);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


Cha*_*Sun 5

Convert函数对我不起作用,最终这成功了:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    return new SolidColorBrush((Color)value);
}
Run Code Online (Sandbox Code Playgroud)