HandyControl控件库线上说明见:
https://handyorg.github.io/handycontrol/native_controls/
程序运行效果:


MainWindow.xaml
<Window x:Class="WpfApp1.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:WpfApp1"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel Orientation="Horizontal" Margin="5">
<Label Content="转换器" FontSize="16" Margin="5"/>
<Label Content="看我" Background="Red" Foreground="White" FontSize="16" Margin="5"
Visibility="{Binding IsChecked,Converter={StaticResource Bool2Visility},ConverterParameter=true}"/>
<CheckBox Content="点我" IsChecked="{Binding IsChecked}" FontSize="16" Margin="5"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="5">
<TextBox Name="TB_Binding" hc:TitleElement.TitlePlacement="Left" hc:TitleElement.Title="后台绑定"
Style="{DynamicResource TextBoxExtend}" VerticalAlignment="Center" Margin="5" FontSize="16"/>
<TextBox hc:TitleElement.TitlePlacement="Left" hc:TitleElement.Title="带格式绑定"
Style="{DynamicResource TextBoxExtend}" VerticalAlignment="Center"
FontSize="16" Foreground="{DynamicResource PrimaryBrush}"
Text="{Binding FontSize,StringFormat={}$pre {0:F3} ext%}"/>
<TextBox hc:TitleElement.TitlePlacement="Left" hc:TitleElement.Title="鼠标位置" Margin="5"
Style="{DynamicResource TextBoxExtend}" VerticalAlignment="Center"
FontSize="16" Text="{Binding ShowingText}"/>
<Button Style="{StaticResource ButtonPrimary}" Content="点击显示通知"
Command="{Binding ShowNotificationCommand}"/>
<ScrollViewer VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Right">
<StackPanel hc:Growl.GrowlParent="True" VerticalAlignment="Top" Margin="0,10,10,10"/>
</ScrollViewer>
<TabControl Margin="10" Style="{StaticResource TabControlCapsule}">
<TabItem Header="选项卡1">
</TabItem>
<TabItem Header="选项卡2">
</TabItem>
<TabItem Header="选项卡3">
</TabItem>
</TabControl>
<Slider VerticalAlignment="Center" Width="400" Value="40" Maximum="100"/>
<ComboBox ItemsSource="{Binding DataList}" SelectedIndex="0" hc:InfoElement.Title="这是标题" Style="{StaticResource ComboBoxExtend}" Text="正文1"/>
<hc:ButtonGroup HorizontalAlignment="Left" Margin="5">
<RadioButton hc:IconElement.Geometry="{DynamicResource Icon_Module_Rect}"
hc:BorderElement.CornerRadius="0" BorderThickness="0"
Margin="2" Padding="5" Cursor="Hand" ToolTip="矩形" hc:IconElement.Height="24"
hc:IconElement.Width="24" Height="36"
IsChecked="{Binding CurModule,Converter={StaticResource ModuleType2Bool},ConverterParameter=1}"
Command="{Binding CmdSwitchModule}"/>
<RadioButton hc:IconElement.Geometry="{DynamicResource Icon_Module_Circle}"
hc:BorderElement.CornerRadius="0" BorderThickness="0"
Margin="2" Padding="5" Cursor="Hand" ToolTip="圆"
hc:IconElement.Height="24" hc:IconElement.Width="24" Height="36"
IsChecked="{Binding CurModule,Converter={StaticResource ModuleType2Bool},ConverterParameter=2}"
Command="{Binding CmdSwitchModule}"/>
<RadioButton hc:IconElement.Geometry="{DynamicResource Icon_Module_Polygon}"
hc:BorderElement.CornerRadius="0" BorderThickness="0"
Margin="2" Padding="5" Cursor="Hand" ToolTip="多边形"
hc:IconElement.Height="24" hc:IconElement.Width="24" Height="36"
IsChecked="{Binding CurModule,Converter={StaticResource ModuleType2Bool},ConverterParameter=3}"
Command="{Binding CmdSwitchModule}"/>
<RadioButton hc:IconElement.Geometry="{DynamicResource Icon_Module_Mask}"
hc:BorderElement.CornerRadius="0" BorderThickness="0"
Margin="2" Padding="5" Cursor="Hand" ToolTip="掩膜"
hc:IconElement.Height="24" hc:IconElement.Width="24" Height="36"
IsChecked="{Binding CurModule,Converter={StaticResource ModuleType2Bool},ConverterParameter=4}"
Command="{Binding CmdSwitchModule}"/>
<Button hc:IconElement.Geometry="{DynamicResource Icon_Module_Clear}"
hc:BorderElement.CornerRadius="0" BorderThickness="0"
Margin="2" Padding="5" Cursor="Hand" ToolTip="清空"
hc:IconElement.Height="24" hc:IconElement.Width="24" Height="36"
Command="{Binding CmdWithParameter}"
CommandParameter="{Binding RelativeSource={RelativeSource Self},Path=ToolTip}"/>
<Button hc:IconElement.Geometry="{DynamicResource Icon_Zoom_Fit}"
hc:BorderElement.CornerRadius="0" BorderThickness="0"
Margin="2" Padding="5" Cursor="Hand" ToolTip="图像自适应"
hc:IconElement.Height="24" hc:IconElement.Width="24" Height="36"
Command="{Binding CmdWithParameter}"
CommandParameter="{Binding RelativeSource={RelativeSource Self},Path=ToolTip}"/>
</hc:ButtonGroup>
</StackPanel>
</Grid>
</Window>MainWindow.xaml.cs
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApp1.ViewModel;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : System.Windows.Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new MainViewModel();
}
}
}MainViewModel.cs
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using HandyControl.Controls;
namespace WpfApp1.ViewModel
{
public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
private bool isChecked=true;
[RelayCommand]
private void ShowNotification()
{
Growl.Success("显示一条通知!");
}
}
}Geometry.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:o="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"> <Geometry o:Freeze="True" x:Key="Icon_Module_Circle">M512 85.333C276.48 85.333 85.333 276.48 85.333 512S276.48 938.667 512 938.667 938.667 747.52 938.667 512 747.52 85.333 512 85.333z m0 768c-188.587 0-341.333-152.746-341.333-341.333S323.413 170.667 512 170.667 853.333 323.413 853.333 512 700.587 853.333 512 853.333z</Geometry> <Geometry o:Freeze="True" x:Key="Icon_Module_Rect">M896 801.632V222.368c36.48-7.424 64-39.744 64-78.368C960 99.904 924.128 64 880 64c-38.656 0-70.944 27.52-78.368 64H222.368A80.096 80.096 0 0 0 144 64 80.096 80.096 0 0 0 64 144c0 38.624 27.52 70.944 64 78.368V801.6c-36.48 7.424-64 39.744-64 78.368A80.096 80.096 0 0 0 144 960c38.624 0 70.944-27.52 78.368-64H801.6c7.424 36.48 39.744 64 78.368 64A80 80 0 1 0 896 801.632z m-704 14.784V207.584c5.888-4.448 11.136-9.696 15.584-15.584h608.8c4.48 5.888 9.696 11.136 15.584 15.584v608.8c-5.92 4.48-11.136 9.696-15.616 15.616H207.584A79.04 79.04 0 0 0 192 816.416z</Geometry> <Geometry o:Freeze="True" x:Key="Icon_Module_Polygon">m 262.69111,27.682766 c -72.39562,0 -132.72545,56.304696 -132.72545,128.700324 0,53.22987 32.7414,99.71668 78.78689,120.71606 L 138.69462,737.6508 C 78.759617,747.72894 29.412939,802.48133 29.412939,864.25843 c 0,68.37365 60.326676,128.70033 128.700321,128.70033 63.97348,0 115.22884,-47.1446 126.32484,-105.28484 l 472.71187,-56.48373 c 22.53968,36.05934 62.22983,61.21584 108.83863,61.21584 68.37365,0 128.70033,-64.3518 128.70033,-132.72545 0,-61.04261 -44.99267,-115.34919 -106.13323,-126.36254 L 858.18344,379.44291 c 38.49378,-22.85374 64.10979,-64.6044 64.10979,-110.44114 0,-68.37365 -60.32668,-128.70033 -128.70033,-128.70033 -43.47247,0 -83.53632,24.48282 -107.06645,59.82072 L 389.80778,140.87646 C 382.02027,79.200988 329.50912,27.682766 262.69111,27.682766 Z m 0,80.436524 c 28.15386,0 48.2638,20.10994 48.2638,48.2638 0,28.15386 -28.15705,48.2638 -52.28892,48.2638 -24.13187,0 -48.2638,-24.13193 -48.2638,-48.2638 0,-24.13187 24.13506,-48.2638 52.28892,-48.2638 z M 793.5929,216.71284 c 28.15386,0 48.2638,24.13193 48.2638,48.2638 0,24.13187 -24.13192,48.2638 -48.2638,48.2638 -24.13187,0 -48.2638,-24.13193 -48.2638,-48.2638 0,-24.13187 20.10995,-48.2638 48.2638,-48.2638 z m -419.32946,3.08247 291.53409,58.19936 c 4.39085,59.90539 51.29251,111.10609 113.37279,118.21803 l 29.8538,249.59548 c -39.42677,20.9815 -66.55275,62.01104 -70.60466,106.59513 L 272.98488,808.0198 c -11.93622,-24.02497 -31.07497,-43.95239 -54.99434,-56.82309 l 70.73663,-464.95383 c 37.24653,-8.23912 67.6715,-33.87321 85.53627,-66.44757 z M 865.9886,711.41678 c 24.13187,0 48.2638,24.13507 48.2638,52.28893 0,28.15386 -24.13193,44.23867 -48.2638,44.23867 -24.13187,0 -48.2638,-24.13193 -48.2638,-48.2638 0,-24.13187 20.10995,-48.2638 48.2638,-48.2638 z M 158.11326,811.96951 c 28.15386,0 48.2638,28.15705 48.2638,52.28892 0,24.13187 -24.13193,48.2638 -48.2638,48.2638 -24.13187,0 -48.2638,-28.15705 -48.2638,-52.28892 0,-24.13187 20.10994,-48.2638 48.2638,-48.2638 z</Geometry> <Geometry o:Freeze="True" x:Key="Icon_Module_Mask">M592 368V128a16 16 0 0 0-16-16H128a16 16 0 0 0-16 16v448a16 16 0 0 0 16 16h240V416a48 48 0 0 1 48-48h176z M448 416h448a32 32 0 0 1 32 32v448a32 32 0 0 1-32 32H448a32 32 0 0 1-32-32V448a32 32 0 0 1 32-32z m0 32v448h448V448H448z</Geometry> <Geometry o:Freeze="True" x:Key="Icon_Module_Clear">M901.3 504.8l-76.3-150c-13.4-26.3-40-42.6-69.5-42.6H639c-1.1 0-2-0.9-2-2V120.6c0-31.1-25.3-56.3-56.3-56.3h-90c-31.1 0-56.3 25.3-56.3 56.3v189.6c0 1.1-0.9 2-2 2H315.8c-29.5 0-56.1 16.3-69.5 42.6l-76.3 150c-9.2 18.1-8.4 39.3 2.2 56.6 10.3 16.8 27.9 27 47.4 27.6-4.8 101-38.3 205.9-90.2 279.5-12.5 17.8-14.1 40.8-4.1 60.1 10 19.3 29.7 31.3 51.5 31.3h601.5c35 0 66-23.6 75.2-57.4 15.5-56.5 28.4-107.9 29.4-164.9C884 685 874 636 852.9 589c19-1.1 36.1-11.2 46.2-27.6 10.6-17.3 11.4-38.5 2.2-56.6z m-681.4 25.4l76.3-150c3.8-7.4 11.3-12 19.6-12h116.4c32 0 58-26 58-58V120.6c0-0.1 0.2-0.3 0.3-0.3h90c0.1 0 0.3 0.2 0.3 0.3v189.6c0 32 26 58 58 58h116.4c8.3 0 15.8 4.6 19.6 12l76.3 150c0.2 0.3 0.5 1-0.1 2s-1.3 1-1.7 1H221.7c-0.4 0-1.1 0-1.7-1-0.6-1-0.3-1.7-0.1-2zM827 736.6c-0.9 50.5-12.9 98.3-27.4 151.1-2.6 9.5-11.3 16.2-21.2 16.2H651.8c11.3-22.3 18.5-44 23.1-61.2 7.1-26.7 10.7-53.5 10.6-78-0.1-17.1-15.5-30.1-32.4-27.4-13.6 2.2-23.6 14-23.6 27.8 0.1 42.7-14.1 98.2-42.7 138.8H406.2c15.2-21.7 26.1-43.8 33.6-61.9 10-24.3 17.4-49.7 21.2-72.5 2.8-17-10.4-32.5-27.6-32.5-13.6 0-25.3 9.8-27.6 23.3-2.8 16.6-8.3 37.7-17.7 60.4-10.1 24.6-27.8 58.1-55.6 83.3H176.9c-0.5 0-1.2 0-1.8-1.1-0.6-1.1-0.2-1.6 0.1-2 29.7-42.1 54.8-94.5 72.5-151.4 16.2-52.1 25.7-106.9 28-160.3h514.6C816 635.6 828 684 827 736.6z</Geometry> <Geometry x:Key="Icon_Zoom_Fit" o:Freeze="True">M474.52 59.68c-231.9 0-419.89 187.99-419.89 419.89 0 231.902 187.99 419.9 419.89 419.9 103.116 0 197.425-37.32 270.51-98.99l153.96 153.94 4.79 4.12c16.705 12.392 40.405 11.02 55.55-4.13 16.661-16.664 16.655-43.679-0.01-60.34L804.25 739.03c56.304-71.454 90.17-161.43 90.17-259.46 0-231.9-187.998-419.89-419.9-419.89z m0 85.33c184.773 0 334.57 149.787 334.57 334.56 0 93.402-38.368 177.776-100.09 238.47L651.14 507.3l-57.88 58.66-82.76-81.66 81.9-83.58 60.69 59.47 56.13-218.82-217.63 60.57 60.74 59.52-81.76 83.44-79.96-78.89 61.27-62.53-218.06-55.94c60.852-63.112 146.106-102.53 240.7-102.53zM233.28 248.14l60.35 216.84 57.72-58.91 79.96 78.89-77.25 78.84-61.42-59.76-53.83 212.88c-61.026-60.607-98.85-144.546-98.85-237.35 0-89.888 35.64-171.318 93.32-231.43z m237.96 276.22l82.63 81.52-57.83 58.62 211.36 55c-60.242 58.482-142.288 94.64-232.88 94.64-90.99 0-173.387-36.45-233.7-95.39l211.24-59.58-57.8-56.25z</Geometry> </ResourceDictionary>
ModuleType.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApp1.Model
{
public enum ModuleType
{
None = 0,
Rect,
Circle,
Polygon,
Mask,
}
}App.xaml
<Application x:Class="WpfApp1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApp1" xmlns:converter="clr-namespace:WpfApp1.Converter" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml" /> <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml" /> <ResourceDictionary Source="Resource\Geometry.xaml"/> </ResourceDictionary.MergedDictionaries> <converter:ModuleTypeToBoolConverter x:Key="ModuleType2Bool"/> <converter:BoolToVisibilityConverter x:Key="Bool2Visility"/> </ResourceDictionary> </Application.Resources> </Application>
BoolToVisibilityConverter.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows;
namespace WpfApp1.Converter
{
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value)
{
return Visibility.Visible;
}
else
{
return Visibility.Collapsed;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}ModuleTypeToBoolConverter.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using WpfApp1.Model;
namespace WpfApp1.Converter
{
public class ModuleTypeToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
ModuleType type = (ModuleType)value;
if (parameter == null)
{
return false;
}
return (int)type == int.Parse(parameter.ToString());
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
int flag = int.Parse(parameter.ToString());
return (ModuleType)flag;
}
}
}