Skip to content

Color picker and font picker add-ons built for WPF. 为WPF打造的颜色选择器和字体选择器。

License

Notifications You must be signed in to change notification settings

tp1415926535/ColorFontPickerWPF

Repository files navigation

ColorFontPickerWPF

Color picker and font picker add-ons built for WPF.
Includes ColorDialog, ColorPickerControl, ColorPickerPopup, FontDialog, FontPickerControl, FontPickerPopup .
Dialogs follow Winform design, controls can be added directly in xaml and support collapsing.
The interface automatically displays the corresponding language according to the threads, the localization includes 14 languages.

为WPF打造的颜色选择器和字体选择器附加功能。
包括颜色对话框、颜色选择控件、颜色选择下拉、字体对话框、字体选择控件、字体选择下拉。
对话框沿用Winform的设计,控件可以直接在xaml中插入并支持折叠。
界面根据线程自动显示对应语言,本地化包括14种语言。

ColorDialog:
ColorDialog

ColorPickerPopup:
ColorPickerPopup

FontDialog:
FontDialog

FontPickerPopup:
FontPickerPopup

release nuget license C#

Description 说明

English Description

Usage

Download package from Nuget, or using the release Dll.

Color

ColorDialog

Just like winform's way:

using ColorFontPickerWPF;

ColorDialog colorDialog = new ColorDialog();
//colorDialog.SelectedColor = ((SolidColorBrush)label.Background).Color; //In need
if (colorDialog.ShowDialog() == true)
    label.Background = new SolidColorBrush(colorDialog.SelectedColor);

ColorPickerControl

ColorPickerControl-Style1:
ColorPickerControl

ColorPickerControl-Style2:
ColorPickerControl2

Additional Property "SelectedColor" can be get and set.
Additional Property "WithoutColorCells" can collapse the left interface when True.

  • The xaml way
xmlns:cf="clr-namespace:ColorFontPickerWPF;assembly=ColorFontPickerWPF"
        
<cf:ColorPickerControl Width="auto" Height="auto" SelectedColor="Blue" WithoutColorCells="False"/>
  • The C# way
using ColorFontPickerWPF;

var colorPicker = new ColorPickerControl();
//colorPicker.SelectedColor = Colors.Red; //In need
grid.Children.Add(colorPicker);

ColorPickerPopup

ColorPickerPopup

Additional Property "SelectedColor" can be get and set.
Additional Property "ColorText" can show current color value , support 'None','RGB','HEX','HSL' .

ColorText = "RGB":
ColorPickerPopup-text1

ColorText = "HEX":
ColorPickerPopup-text2

ColorText = "HSL":
ColorPickerPopup-text3

  • The xaml way
xmlns:cf="clr-namespace:ColorFontPickerWPF;assembly=ColorFontPickerWPF"
        
<cf:ColorPickerPopup SelectedColor="Yellow" ColorText="RGB"/>
  • The C# way
using ColorFontPickerWPF;

var colorPicker = new ColorPickerPopup();
//colorPicker.SelectedColor = Colors.Red; //In need
grid.Children.Add(colorPicker);

Font

FontDialog

To make it easier to use, methods to get and set fonts are provided:

using ColorFontPickerWPF;

FontDialog fontDialog = new FontDialog();
//fontDialog.GetFont(textBlock); //In need
if (fontDialog.ShowDialog() == true)
    fontDialog.SetFont(textBlock);

FontPickerControl

FontPickerControl-style1:
FontPickerControl

FontPickerControl-style2:
FontPickerControl2

FontPickerControl-style3:
FontPickerControl3

Additional Property "SelectedFont" can be get and set.
Additional Property "WithoutDecorations" and "WithoutPreviewRow" can collapse corresponding area when True.

  • The xaml way
xmlns:cf="clr-namespace:ColorFontPickerWPF;assembly=ColorFontPickerWPF"
        
<cf:FontPickerControl Width="auto" Height="auto" WithoutDecorations="False" WithoutPreviewRow="False"/>

FontPickerPopup

FontPickerPopup

Additional Property "SelectedFont" can be get and set.
Additional Property "FontText" can view current font style, default value is 'FontSize: {fontsize}px'. You can write something else, and '{fontsize}' will be replace to font size value.

FontText="":
ColorPickerPopup-text1

FontText="Font Example":
ColorPickerPopup-text2

FontText="Size:{fontsize}":
ColorPickerPopup-text3

  • The xaml way
xmlns:cf="clr-namespace:ColorFontPickerWPF;assembly=ColorFontPickerWPF"
        
<cf:FontPickerPopup FontText=""/>
  • The C# way
using ColorFontPickerWPF;

var fontPicker = new FontPickerPopup();
/*//In need
fontPicker.SelectedFont = new Font()
{ 
    FontFamily = new FontFamily("Microsoft YaHei UI"), 
    FamilyTypeface = new FamilyTypeface(),
    FontSize = 12
}; 
//fontPicker.Get(textBlock);// or get font from control
*/
grid.Children.Add(fontPicker);

Additional information

  • ColorPicker reference Winform design, in addition to RGB and HSL, HEX format has been added, and added a full screen color picking function.
  • SelectedFont is an instance of the "Font" class. It is structured as follows:
public class Font
{
    public FontFamily FontFamily { get; set;}
    public FamilyTypeface FamilyTypeface { get; set;}       
    public TextDecorationType TextDecorationType { get; set;}
    public double FontSize { get; set;}
}

public enum TextDecorationType
{
    None,
    OverLine,
    Strikethrough,
    Baseline,
    Underline,
}

You can handle SelectedFont yourself, or use a wrapped method to "fontDialog.GetFont()", "fontPickerControl.GetFont()", "fontPickerPopup.GetFont()", or "fontDialog.SetFont()", "fontPickerControl.SetFont()" , "fontPickerPopup.SetFont()" directly.

  • The interface language is displayed automatically according to the current thread, or you can specify the interface language manually:
using ColorFontPickerWPF;

PickerLanguageManager.settings.UIculture = new CultureInfo("en-US");

14 languages are currently supported, including: Chinese, English, Arabic, Czech, German, Spanish, French, Hungarian, Italian, Japanese, Portuguese, Romanian, Russian, and Swedish.

Version

  • v1.0.4 2022/12/25 Fix the color dialog language, optimize the method of switching language, no longer force to change to current language before loading.
  • v1.0.3 2022/10/17 Add popup control, optimize color control's slider visual effect.
  • v1.0.2 2022/10/15 Fix the bug that some parts are not updated after the assignment.
  • v1.0.1 2022/10/14 Removed the use of color library, color conversion was changed to self-implemented. Fixed bugs in font dialog. added multi-language support, expanded from 2 to 14 languages.
  • v1.0.0 2022/10/13 Basic features. Dialogs and selection controls.

中文说明

颜色对话框:
颜色对话框

颜色选择下拉:
颜色选择下拉

字体对话框:
字体对话框

字体选择下拉:
字体选择下拉

使用

从Nuget下载包,或者引用Release中的dll。

颜色

颜色对话框(ColorDialog)

跟 Winform 一样调用:

using ColorFontPickerWPF;

ColorDialog colorDialog = new ColorDialog();
//colorDialog.SelectedColor = ((SolidColorBrush)label.Background).Color; //如果需要显示当前值
if (colorDialog.ShowDialog() == true)
    label.Background = new SolidColorBrush(colorDialog.SelectedColor);

颜色选择控件(ColorPickerControl)

颜色选择控件-样式1:
颜色选择控件1

颜色选择控件-样式2:
颜色选择控件2

附加属性“SelectedColor”(选择的颜色)可以设置和获取。
附加属性“WithoutColorCells”(不要颜色格子)为True的时候可以折叠左边部分。

  • 用 xaml 的方式
xmlns:cf="clr-namespace:ColorFontPickerWPF;assembly=ColorFontPickerWPF"
        
<cf:ColorPickerControl Width="auto" Height="auto" SelectedColor="Blue" WithoutColorCells="False"/>
  • 用 C# 的方式
using ColorFontPickerWPF;

var colorPicker = new ColorPickerControl();
//colorPicker.SelectedColor = Colors.Red; //如果需要显示当前值
grid.Children.Add(colorPicker);

颜色选择下拉(ColorPickerPopup)

颜色选择下拉

附加属性“SelectedColor”(选择的颜色)可以设置和获取。
附加属性“ColorText”(颜色文本)可以显示当前颜色值,支持颜色模型:"None","RGB","HEX","HSL"。

ColorText = "RGB":
颜色选择下拉-文本1

ColorText = "HEX":
颜色选择下拉-文本2

ColorText = "HSL":
颜色选择下拉-文本3

  • 用 xaml 的方式
xmlns:cf="clr-namespace:ColorFontPickerWPF;assembly=ColorFontPickerWPF"
        
<cf:ColorPickerPopup SelectedColor="Yellow" ColorText="RGB"/>
  • 用 C# 的方式
using ColorFontPickerWPF;

var colorPicker = new ColorPickerPopup();
//colorPicker.SelectedColor = Colors.Red; //如果需要显示当前值
grid.Children.Add(colorPicker);

字体

字体对话框(FontDialog)

为了更便于使用,字体提供了获取和设置的封装方法:

using ColorFontPickerWPF;

FontDialog fontDialog = new FontDialog();
//fontDialog.GetFont(textBlock); //如果需要显示当前值
if (fontDialog.ShowDialog() == true)
    fontDialog.SetFont(textBlock);

字体选择控件(FontPickerControl)

字体选择控件-样式1:
字体选择控件1

字体选择控件-样式2:
字体选择控件2

字体选择控件-样式3:
字体选择控件3

附加属性 “SelectedFont”(选择的字体)可以获取和设置。
附加属性 “WithoutDecorations”(不要装饰线设置)和 “WithoutPreviewRow” (不要预览行)值为True的时候可以折叠对应区域。

  • 用 xaml 的方式
xmlns:cf="clr-namespace:ColorFontPickerWPF;assembly=ColorFontPickerWPF"
        
<cf:FontPickerControl Width="auto" Height="auto" WithoutDecorations="False" WithoutPreviewRow="False"/>
  • 用 C# 的方式
using ColorFontPickerWPF;

var fontPicker = new FontPickerControl();
/*//如果需要显示当前值
fontPicker.SelectedFont = new Font()
{ 
    FontFamily = new FontFamily("Microsoft YaHei UI"), 
    FamilyTypeface = new FamilyTypeface(),
    FontSize = 12
}; 
//fontPicker.Get(textBlock);//或者用封装的方法直接获取控件字体
*/
grid.Children.Add(fontPicker);

字体选择下拉(FontPickerPopup)

字体选择下拉

附加属性 “SelectedFont”(选择的字体)可以获取和设置。
附加属性 “FontText”(字体文本) 可以显示当前字体样式,默认显示 'FontSize: {fontsize}px'。可以自定义任何内容,并且“{fontsize}”可以作为变量显示当前字号。

FontText="":
字体选择下拉-文本1

FontText="字体预览":
字体选择下拉-文本2

FontText="字号:{fontsize}px":
字体选择下拉-文本3

  • 用 xaml 的方式
xmlns:cf="clr-namespace:ColorFontPickerWPF;assembly=ColorFontPickerWPF"
        
<cf:FontPickerPopup FontText=""/>
  • 用 C# 的方式
using ColorFontPickerWPF;

var fontPicker = new FontPickerPopup();
/*//如果需要显示当前值
fontPicker.SelectedFont = new Font()
{ 
    FontFamily = new FontFamily("Microsoft YaHei UI"), 
    FamilyTypeface = new FamilyTypeface(),
    FontSize = 12
}; 
//fontPicker.Get(textBlock);//或者用封装的方法直接获取控件字体
*/
grid.Children.Add(fontPicker);

补充说明

  • 颜色选择器沿用Winform的设计,处理RGB、HSL之外还增加了HEX格式,另外还有全屏取色的功能。
  • “SelectedFont” (选择的字体)是 “Font” 类的实例,它的结构如下:
public class Font
{
    public FontFamily FontFamily { get; set;}
    public FamilyTypeface FamilyTypeface { get; set;}       
    public TextDecorationType TextDecorationType { get; set;}
    public double FontSize { get; set;}
}

public enum TextDecorationType
{
    None,
    OverLine,
    Strikethrough,
    Baseline,
    Underline,
}

你可以自行处理 “SelectedFont” 的值,或者直接使用封装的方法"fontDialog.GetFont()", "fontPickerControl.GetFont()", "fontPickerPopup.GetFont()" 或者 "fontDialog.SetFont()", "fontPickerControl.SetFont()", "fontPickerPopup.SetFont()"。

  • 界面语言根据当前线程自动显示,你也可以手动指定界面语言:
using ColorFontPickerWPF;

PickerLanguageManager.settings.UIculture = new CultureInfo("en-US");

目前支持14种语言,包括:中文,英语,阿拉伯语,捷克语,德语,西班牙语,法语,匈牙利语,意大利语,日语,葡萄牙语,罗马尼亚语,俄语,瑞典语。

版本

  • v1.0.4 2022/12/25 修复颜色对话框语言,优化切换语言方法,不再加载前强制改为当前语言。
  • v1.0.3 2022/10/17 添加下拉控件,优化颜色控件的滑动条视觉效果。
  • v1.0.2 2022/10/15 修复赋值之后部分不更新的bug。
  • v1.0.1 2022/10/14 移除了对颜色库的使用,颜色转换改为自行实现。字体对话框修复bug。新增多语言支持,从2种语言扩展到14种。
  • v1.0.0 2022/10/13 基本功能。对话框和选择控件。

About

Color picker and font picker add-ons built for WPF. 为WPF打造的颜色选择器和字体选择器。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages