WPF自定义按钮控件

这篇具有很好参考价值的文章主要介绍了WPF自定义按钮控件。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

WPF自定义按钮控件

在平时的WPF应用中,系统提供的按钮控件确实可以实现正常的逻辑,但是从视觉方面看的话,确实不够美观,而且每个项目的UI设计不尽相同。那么自定义按钮控件就是必须的了,网上查找了很多自定义按钮控件的办法,但每次都是写到一半就报错。在参考了多个技术贴之后,自己写出了第一个自定义的按钮控件,欢迎参考,如有错误,敬请指正。

参考文档

http://t.zoukankan.com/DoNetCoder-p-3732310.html
https://blog.51cto.com/u_15076204/4542004
https://www.cnblogs.com/donetcoder/p/3732310.html?utm_source=tuicool&utm_medium=referral

1.创建自定义控件库

名称自己定,平台根据实际情况选择,这里使用的是.Net Core6.0平台
WPF自定义按钮控件

2.改名

自定义控件库创建完成后,可以根据实际情况自己修改“CustomControl1.cs”的名称。此处我的命名是“ImageButton.cs”
WPF自定义按钮控件
打开ImageButton.cs,内容如下(里面只有一个很长的使用说明和构造方法):

namespace CustomControls
{
    /// <summary>
    /// 按照步骤 1a 或 1b 操作,然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
    ///
    /// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
    /// 元素中: 
    ///
    ///     xmlns:MyNamespace="clr-namespace:ImageButton"
    ///
    ///
    /// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
    /// 元素中: 
    ///
    ///     xmlns:MyNamespace="clr-namespace:ImageButton;assembly=ImageButton"
    ///
    /// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用,
    /// 并重新生成以避免编译错误: 
    ///
    ///     在解决方案资源管理器中右击目标项目,然后依次单击
    ///     “添加引用”->“项目”->[选择此项目]
    ///
    ///
    /// 步骤 2)
    /// 继续操作并在 XAML 文件中使用控件。
    ///
    ///     <MyNamespace:CustomControl1/>
    ///
    /// </summary>

    public class ImageButton : System.Windows.Controls.Button
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        static ImageButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(typeof(ImageButton)));
        }

    }
}

3.添加要用的资源

创建资源文件夹并向内拷贝用到的资源文件:有的说需要把拷贝进去的资源属性中的“生成操作”手动改为“资源”或“Resource”,我本人在拷贝后并没有发现需要设置,可能不同的环境,每个人的情况不尽相同,此处需要灵活处理。
WPF自定义按钮控件

4.编写Themes下Generic.xaml样式文件

其中包含样式设置,及对应的触发器设置,由于想要最大限度的做到通用,所以很多属性都由绑定的形式交给属性绑定类(ImageButton.cs)处理。

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:CustomControls">
    <Style TargetType="{x:Type local:ImageButton}" BasedOn="{StaticResource {x:Type Button}}">
        <Setter Property="Foreground" Value="#F5F7FF"/>
        <!--<Setter Property="Background" Value="#536DE0"/>-->
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="FontWeight" Value="Medium"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ImageButton}">
                    <Border x:Name="Normal" CornerRadius="{Binding CornerRadius,RelativeSource={RelativeSource TemplatedParent}}" MinHeight="{TemplateBinding MinHeight}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                        <Grid >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="{Binding IconColumnWidth,RelativeSource={RelativeSource TemplatedParent}}"/>
                                <ColumnDefinition Width="{Binding TextColumnWidth,RelativeSource={RelativeSource TemplatedParent}}"/>
                            </Grid.ColumnDefinitions>

                            
                            <Image x:Name="back" Grid.ColumnSpan="2" Margin="{Binding ButtonBackgroundMargin,RelativeSource={RelativeSource TemplatedParent}}"
                                   Source="{Binding NormalButtonBackground,RelativeSource={RelativeSource TemplatedParent}}"
                                   VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Stretch="Fill" />
                            <Image x:Name="IconImg" Grid.Column="0"  Width="14" Height="14"
                                   Source="{Binding NormalIcon,RelativeSource={RelativeSource TemplatedParent}}"
                                   IsEnabled="{TemplateBinding IsEnabled}"
                                   Effect="{x:Null}"
                                   VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
                                   Stretch="UniformToFill " StretchDirection="Both" Margin="15,2,0,2"/>
                            <TextBlock x:Name="TextBlockInternal" Grid.Column="1" 
                                       Text="{Binding Text,RelativeSource={RelativeSource TemplatedParent}}"
                                       Effect="{TemplateBinding Effect}"
                                       HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                       TextAlignment="{Binding ButtonTextAlignment,RelativeSource={RelativeSource TemplatedParent}}" Margin="2,0"/>
                        </Grid>
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Foreground" Value="#4D528A"/>
                            <!--<Setter Property="Background" Value="#D0D4EA"/>-->
                            <Setter TargetName="back" 
                                    Property="Source" Value="{Binding HoverButtonBackground,RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Setter TargetName="IconImg" 
                                    Property="Source" Value="{Binding HoverIcon,RelativeSource={RelativeSource TemplatedParent}}"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Foreground" Value="#CAD3F9"/>
                            <!--<Setter Property="Background" Value="#152B7E" />-->
                            <Setter TargetName="back" 
                                    Property="Source" Value="{Binding PressedButtonBackground,RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Setter TargetName="IconImg" 
                                    Property="Source" Value="{Binding PressedIcon,RelativeSource={RelativeSource TemplatedParent}}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Opacity" Value=".6"/>
                            <Setter Property="Effect" Value="{x:Null}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

5.绑定属性类编写

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;

namespace CustomControls
{
    /// <summary>
    /// 按照步骤 1a 或 1b 操作,然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
    ///
    /// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
    /// 元素中: 
    ///
    ///     xmlns:MyNamespace="clr-namespace:ImageButton"
    ///
    ///
    /// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
    /// 元素中: 
    ///
    ///     xmlns:MyNamespace="clr-namespace:ImageButton;assembly=ImageButton"
    ///
    /// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用,
    /// 并重新生成以避免编译错误: 
    ///
    ///     在解决方案资源管理器中右击目标项目,然后依次单击
    ///     “添加引用”->“项目”->[选择此项目]
    ///
    ///
    /// 步骤 2)
    /// 继续操作并在 XAML 文件中使用控件。
    ///
    ///     <MyNamespace:CustomControl1/>
    ///
    /// </summary>

    public class ImageButton : System.Windows.Controls.Button
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        static ImageButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(typeof(ImageButton)));
        }

        /// <summary>
        /// 按钮文本属性
        /// </summary>
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register("ButtonText", typeof(string), typeof(FrameworkElement));
        public string Text
        {
            set
            {
                SetValue(TextProperty, value);
            }
            get
            {
                return (string)GetValue(TextProperty);
            }
        }

        /// <summary>
        /// 按钮圆角属性
        /// </summary>
        public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(int), typeof(FrameworkElement));
        public int CornerRadius
        {
            set
            {
                SetValue(CornerRadiusProperty, value);
            }
            get
            {
                return (int)GetValue(CornerRadiusProperty);
            }
        }

        /// <summary>
        /// 按钮图标属性(常规)
        /// </summary>
        public static readonly DependencyProperty NormalIconProperty = DependencyProperty.Register("NormalIcon", typeof(string), typeof(FrameworkElement));
        public string NormalIcon
        {
            set
            {
                SetValue(NormalIconProperty, value);
            }
            get
            {
                return (string)GetValue(NormalIconProperty);
            }
        }

        /// <summary>
        /// 按钮图标属性(鼠标悬停)
        /// </summary>
        public static readonly DependencyProperty HoverIconProperty = DependencyProperty.Register("HoverIcon", typeof(string), typeof(FrameworkElement));
        public string HoverIcon
        {
            set
            {
                SetValue(HoverIconProperty, value);
            }
            get
            {
                return (string)GetValue(HoverIconProperty);
            }
        }

        /// <summary>
        /// 按钮图标属性(点击)
        /// </summary>
        public static readonly DependencyProperty PressedIconProperty = DependencyProperty.Register("PressedIcon", typeof(string), typeof(FrameworkElement));
        public string PressedIcon
        {
            set
            {
                SetValue(PressedIconProperty, value);
            }
            get
            {
                return (string)GetValue(PressedIconProperty);
            }
        }

        /// <summary>
        /// 按钮图标列宽度属性
        /// </summary>
        public static readonly DependencyProperty IconColumnWidthProperty = DependencyProperty.Register("IconColumnWidth", typeof(string), typeof(FrameworkElement));
        public string IconColumnWidth
        {
            set
            {
                SetValue(IconColumnWidthProperty, value);
            }
            get
            {
                return (string)GetValue(IconColumnWidthProperty);
            }
        }

        /// <summary>
        /// 按钮文字列高度属性
        /// </summary>
        public static readonly DependencyProperty TextColumnWidthProperty = DependencyProperty.Register("TextColumnWidth", typeof(string), typeof(FrameworkElement));
        public string TextColumnWidth
        {
            set
            {
                SetValue(TextColumnWidthProperty, value);
            }
            get
            {
                return (string)GetValue(TextColumnWidthProperty);
            }
        }

        /// <summary>
        /// 按钮背景图片属性(常规)
        /// </summary>
        public static readonly DependencyProperty NormalButtonBackgroundProperty = DependencyProperty.Register("NormalButtonBackground", typeof(string), typeof(FrameworkElement));
        public string NormalButtonBackground
        {
            set
            {
                SetValue(NormalButtonBackgroundProperty, value);
            }
            get
            {
                return (string)GetValue(NormalButtonBackgroundProperty);
            }
        }

        /// <summary>
        /// 按钮背景图片属性(鼠标悬停)
        /// </summary>
        public static readonly DependencyProperty HoverButtonBackgroundProperty = DependencyProperty.Register("HoverButtonBackground", typeof(string), typeof(FrameworkElement));
        public string HoverButtonBackground
        {
            set
            {
                SetValue(HoverButtonBackgroundProperty, value);
            }
            get
            {
                return (string)GetValue(HoverButtonBackgroundProperty);
            }
        }

        /// <summary>
        /// 按钮背景图片属性(点击)
        /// </summary>
        public static readonly DependencyProperty PressedButtonBackgroundProperty = DependencyProperty.Register("PressedButtonBackground", typeof(string), typeof(FrameworkElement));
        public string PressedButtonBackground
        {
            set
            {
                SetValue(PressedButtonBackgroundProperty, value);
            }
            get
            {
                return (string)GetValue(PressedButtonBackgroundProperty);
            }
        }

        /// <summary>
        /// 按钮背景图片的Margin属性
        /// </summary>
        public static readonly DependencyProperty ButtonBackgroundMarginProperty = DependencyProperty.Register("ButtonBackgroundMargin", typeof(string), typeof(FrameworkElement));
        public string ButtonBackgroundMargin
        {
            set
            {
                SetValue(ButtonBackgroundMarginProperty, value);
            }
            get
            {
                return (string)GetValue(ButtonBackgroundMarginProperty);
            }
        }

        /// <summary>
        /// 按钮文本TextAlignment属性
        /// </summary>
        public static readonly DependencyProperty ButtonTextAlignmentMarginProperty = DependencyProperty.Register("ButtonTextAlignment", typeof(string), typeof(FrameworkElement));
        public string ButtonTextAlignment
        {
            set
            {
                SetValue(ButtonTextAlignmentMarginProperty, value);
            }
            get
            {
                return (string)GetValue(ButtonTextAlignmentMarginProperty);
            }
        }
    }

}

6.使用

使用时创建WPF应用程序(平台一定要对应,否则工具箱里面不会生成可供拖拽的快捷工具)
WPF自定义按钮控件
引入命名空间

 xmlns:controls="clr-namespace:CustomControls;assembly=CustomControls"

调用

<controls:ImageButton Grid.Row="0" Width="104" Height="32" Margin="20"
                                  IconColumnWidth="0.5*" TextColumnWidth="*" ButtonBackgroundMargin="-10" 
                                  ButtonTextAlignment="Left"
                                  NormalIcon="pack://application:,,,/CustomControls;component/Resourse/Images/3.0-相机@2x.png"
                                  HoverIcon="pack://application:,,,/CustomControls;component/Resourse/Images/3.0-相机@2x(1).png"
                                  PressedIcon="pack://application:,,,/CustomControls;component/Resourse/Images/3.0-相机@2x.png" 
                                  NormalButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x.png"
                                  HoverButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(1).png"
                                  PressedButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(2).png"
                                  Text="新增相机" CornerRadius="4"/>

xaml文件整体内容

<Window x:Class="CustomControlDemo.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:CustomControlDemo"
        xmlns:controls="clr-namespace:CustomControls;assembly=CustomControls"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <StackPanel Orientation="Vertical" Height="800">
            <controls:ImageButton Grid.Row="0" Width="104" Height="32" Margin="20"
                                  IconColumnWidth="0.5*" TextColumnWidth="*" ButtonBackgroundMargin="-10" 
                                  ButtonTextAlignment="Left"
                                  NormalIcon="pack://application:,,,/CustomControls;component/Resourse/Images/3.0-相机@2x.png"
                                  HoverIcon="pack://application:,,,/CustomControls;component/Resourse/Images/3.0-相机@2x(1).png"
                                  PressedIcon="pack://application:,,,/CustomControls;component/Resourse/Images/3.0-相机@2x.png" 
                                  NormalButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x.png"
                                  HoverButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(1).png"
                                  PressedButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(2).png"
                                  Text="新增相机" CornerRadius="4"/>
            <controls:ImageButton Grid.Row="1" Width="104" Height="32" Margin="20"
                                  IconColumnWidth="0.5*" TextColumnWidth="*" ButtonBackgroundMargin="-10" 
                                  ButtonTextAlignment="Left"
                                  NormalIcon="pack://application:,,,/CustomControls;component/Resourse/Images/3.0-相机@2x.png"
                                  HoverIcon="pack://application:,,,/CustomControls;component/Resourse/Images/3.0-相机@2x(1).png"
                                  PressedIcon="pack://application:,,,/CustomControls;component/Resourse/Images/3.0-相机@2x.png" 
                                  NormalButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x.png"
                                  HoverButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(1).png"
                                  PressedButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(2).png"
                                  Text="新增视频" CornerRadius="4"/>
            <controls:ImageButton Grid.Row="2" Width="50" Height="50" Margin="20" 
                                  IconColumnWidth="10*" TextColumnWidth="0*" ButtonBackgroundMargin="-20"
                                  ButtonTextAlignment="Center"
                                  NormalButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/笔@2x.png"
                                  HoverButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/笔@2x(1).png"
                                  PressedButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/笔@2x(2).png"
                                  Text="编辑" CornerRadius="4"/>
            <controls:ImageButton Grid.Row="2" Width="50" Height="50" Margin="20"
                                  IconColumnWidth="10*" TextColumnWidth="0*" ButtonBackgroundMargin="-20" 
                                  
                                  NormalButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/编组 34@2x.png"
                                  HoverButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/编组 34@2x(1).png"
                                  PressedButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/编组 34@2x(2).png"
                                  Text="删除" CornerRadius="4"/>
            <controls:ImageButton Grid.Row="3" Width="107" Height="50" Margin="20"
                                  IconColumnWidth="0*" TextColumnWidth="*" ButtonBackgroundMargin="-11,-18" 
                                  ButtonTextAlignment="Center"
                                  NormalButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x.png"
                                  HoverButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(1).png"
                                  PressedButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(2).png"
                                  Text="申请" CornerRadius="4"/>
            <controls:ImageButton Grid.Row="4" Width="216" Height="84" Margin="20"
                                  IconColumnWidth="0*" TextColumnWidth="*" ButtonBackgroundMargin="-23,-29"
                                  ButtonTextAlignment="Center"
                                  NormalButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x.png"
                                  HoverButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(1).png"
                                  PressedButtonBackground="pack://application:,,,/CustomControls;component/Resourse/Images/矩形@2x(2).png"
                                  Text="进入" CornerRadius="4"/>
        </StackPanel>
    </Grid>
</Window>

整体效果

WPF自定义按钮控件文章来源地址https://www.toymoban.com/news/detail-473459.html

到了这里,关于WPF自定义按钮控件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • WPF中用户控件和自定义控件

    无论是在WPF中还是WinForm中,都有用户控件(UserControl)和自定义控件(CustomControl),这两种控件都是对已有控件的封装,实现功能重用。但是两者还是有一些区别,本文对这两种控件进行讲解。 用户控件 注重复合控件的使用,也就是多个现有控件组成一个可复用的控件组

    2024年01月21日
    浏览(33)
  • WPF自定义控件

    方式一:基于现有控件进行扩展,如基于button进行扩展,UI可直接用xmal进行编辑设计,逻辑用xaml.cs进行编辑 方法二:直接创建wpf自定义控件 本文用方法二开展自定义控件!!! 1.自定义控件的内容在代码cs文件中,自定义控件继承自Control,ui界面可在Genric.xaml中定义。 2.在

    2024年02月11日
    浏览(27)
  • wpf 自定义combox控件

    关键步骤 1、新建usercontrol使用基本的控件进行设计 2、依赖属性的定义,目的:外部调用时候能够使用属性进行控件样式的控制 例如 Width=\\\"200\\\" DisplayMemberPath=\\\"Name\\\" SelectedItem=\\\"{Binding SelectedItem,Mode=TwoWay}\\\" SelectionChanged=\\\"{Binding ProjectSelectCommand}\\\" CommandParameter=\\\"{Binding ElementName = Projec

    2024年02月09日
    浏览(31)
  • WPF grid控件定义行和列

    在此已经学习了wpf Grid控件, WPF布局控件Grid的基本使用 - 使用kaxaml_bcbobo21cn的博客-CSDN博客 下面继续学习; 定义3行3列的基本代码如下;为了看清效果,设置 ShowGridLines=\\\"True\\\";   减少一列,效果如下;   只有行,没有列;   指定第一列的宽度;   第一列指定宽度,剩下2列

    2024年02月13日
    浏览(37)
  • wpf 为自定义控件添加滚动条

    在WPF中为自定义控件添加滚动条通常涉及将自定义控件置于 ScrollViewer 控件内,并根据需要配置ScrollViewer的属性。以下是一个基本步骤说明: 创建自定义控件 :首先,你有一个自定义控件(比如名为 RWrapPanel ,继承自 WrapPanel 并实现 IScrollInfo 接口以进行平滑滚动管理)。 嵌

    2024年02月01日
    浏览(30)
  • wpf自定义控件-单/双箭头线

    using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace CustomControls { [TypeDescriptionProvider(typeof(CustomTypeDescriptionProvider))] public class CustomArrow : Shape { public CustomArrow () { Stroke= new SolidColorBrush(Color.FromRgb(0, 140, 206));

    2024年02月15日
    浏览(30)
  • WPF自定义控件库之Window窗口

    在WPF开发中,默认控件的样式常常无法满足实际的应用需求,我们通常都会采用引入第三方控件库的方式来美化UI,使得应用软件的设计风格更加统一。常用的WPF的UI控件库主要有以下几种,如: Modern UI for WPF , MaterialDesignInXamlToolkit ,PanuonUI,Newbeecoder.UI,WPF UI , AduSkin ,

    2024年02月08日
    浏览(33)
  • WPF 自定义控件完成库容表盘显示效果

    先看一下显示效果:        需要注意的地方有以下几点: 表盘的刻度分部,长刻度和短刻度显示。 在数值80W时,需要更改刻度盘的颜色渐变。 在数值80W时,更改库容总数背景的显示,也是颜色渐变。刻度盘控件属性定义: 刻度盘的定义: 设置刻度盘的style: 库容总数背

    2024年02月16日
    浏览(26)
  • WPF自定义控件之ItemsControl鱼眼效果

    原理 先获取鼠标在控件中的坐标,在获取其每一项相对于ItemsControl的坐标,然后计算每一项离当前鼠标的距离,在根据这个距离,对其每一项进行适当的缩放 实现 创建一个类,命名为FishEyeItemsControl   public class FishEyeItemsControl : ItemsControl   添加应用鱼眼效果方法(控制其控

    2024年02月04日
    浏览(29)
  • WPF自定义嵌入弹框控件,支持内容标题自定义

    最近为了实现WPF中弹框组件写了一个小例子: 组件要求: 1.自定义标题 2自定义标题颜色 3提供关闭按钮, 4.弹框内容可由调用方自行嵌入 xaml代码 UserControl x:Class=\\\"WpfApp1.Controls.CustomPopup\\\"              xmlns=\\\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\\\"              xmlns:x=\\\"

    2024年02月16日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包