wpf之颜色选择控件的使用
前言
wpf本身没有颜色选择控件,需要借助第三方库Extended.Wpf.Toolkit来实现
1、下载Extended.Wpf.Toolkit包
Nuget包管理器中下载

通过 xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"引用命名空间。
2、代码
class ViewModelBase : INotifyPropertyChanged{public event PropertyChangedEventHandler PropertyChanged;public void OnPropertyChanged(string propname){if (PropertyChanged != null){PropertyChanged(this, new PropertyChangedEventArgs(propname));}}}
class ViewModel:ViewModelBase{public ViewModel(){}private Color _TestColor = Colors.Gray ;public Color TestColor{get{return _TestColor;}set{_TestColor = value;OnPropertyChanged("TestColor");}}}
ColorPicker 就是用来选择颜色的控件,SelectedColor属性就是颜色的值。
<Window x:Class="wpf之colorPicker.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:wpf之colorPicker"xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Window.Resources><local:BrushToColorConverter x:Key="BrushToColor"/></Window.Resources><Grid><xctk:ColorPicker Name="ColorPicker1" Width=" 150" Height="30" DisplayColorAndName="True" SelectedColor="{Binding TestColor}" /></Grid>
</Window>

马工撰写的年入30万+C#上位机项目实战必备教程(点击下方链接即可访问文章目录)
1、《C#串口通信从入门到精通》
2、《C#与PLC通信从入门到精通 》
3、《C# Modbus通信从入门到精通》
4、《C#Socket通信从入门到精通 》
5、《C# MES通信从入门到精通》
6、《winform控件从入门到精通》
7、《C#操作MySql数据库从入门到精通》
