gpt4 book ai didi

wpf - 新的扩展WPFToolkit ColorPicker

转载 作者:行者123 更新时间:2023-12-04 13:17:47 25 4
gpt4 key购买 nike

我一直在尝试从我的应用程序中使用的工具包中获得新的选色器,但没有成功...

这是示例代码,应该选择窗口背景的颜色来填充当前颜色,并且在重新选择之后,应该将背景颜色更改为选定的颜色...

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

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

最佳答案

这里的问题是Window.Background是画笔,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>

和转换器
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);
}
}
}

关于wpf - 新的扩展WPFToolkit ColorPicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4160510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com