WPF+MVVM案例实战(十七)- 自定义字体图标按钮的封装与实现(ABC类)

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 1、案例效果
  • 1、按钮分类
  • 2、ABC类按钮实现
    • 1、文件创建
    • 2、字体图标资源
    • 3、自定义依赖属性
    • 4、按钮特效样式实现
  • 3、按钮案例演示
    • 1、页面实现与文件创建
    • 2、依赖注入
    • 3 运行效果
    • 4、源代码下载


1、案例效果

在这里插入图片描述

1、按钮分类

在WPF开发中,最常见的就是按钮的使用,这里我们总结以下大概的按钮种类,然后分别实现对应的按钮。

  • A【纯文字按钮】 只有文字,但是会根据根据操作改变颜色
  • B【纯图片按钮 】只有图片,但是会有图片旋转或者变色特效
  • C【文字图片按钮】图片在左,文字在右边,有部分特效
  • D【文字图片按钮】图片在右,文字在左边,有部分特效
  • E【文字图片按钮】图片在上,文字在下,有部分特效
  • F【文字图片按钮】图片在下,文字在上,有部分特效

基本上所有按钮都是上面归纳的情况了,接下来,我们一步一步去实现上面的这些按钮并封装成对应的按钮控件,方便后续使用。

2、ABC类按钮实现

1、文件创建

打开 Wpf_Examples 项目,在自定义控类库中创建文件夹 Buttons ,在Buttons 文件夹下创建 IconFontButton.cs 文件,这里我们将 ABC 三类统称为 字体图标按钮。目录结构如下所示:
在这里插入图片描述

2、字体图标资源

想要做出好看的按钮,离不开一个能随时满足自己需求样式的好图标,这里推荐使用阿里巴巴矢量图标库,一款强大免费的图标库,可以搜索到你想要的图标,随时满足你想要的按钮图标,可以创建项目,把每个项目图标单独分类,简直不要太好。每个项目都可以下载 字体资源,也就是 .ttf 格式的子图文件,有了这个文件,我们使用图标就只需要 图标下面的字体代码即可。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3、自定义依赖属性

  • PressedBackground - 鼠标按下背景样式类型: Brush默认值: Brushes.DarkBlue
  • PressedForeground - 鼠标按下前景样式(图标、文字)类型: Brush默认值:Brushes.White
  • MouseOverBackground - 鼠标进入背景样式类型: Brush默认值: Brushes.RoyalBlue
  • MouseOverForeground - 鼠标进入前景样式类型: Brush默认值: Brushes.White
  • FIcon - 按钮字体图标编码类型: string默认值: “\ue604”
  • FIconSize - 按钮字体图标大小类型: int默认值: 20
  • FIconMargin - 字体图标间距类型: Thickness默认值: new Thickness(0, 1, 3, 1)
  • AllowsAnimation - 是否启用Ficon动画类型: bool 默认值: true
  • CornerRadius - 按钮圆角大小, 左上,右上,右下,左下 默认值: 2
  • ContentDecorations - 内容装饰集合 类型: TextDecorationCollection 默认值: null
    每个依赖属性都有一个对应的属性用于获取和设置其值,并且通过DependencyProperty.Register 方法注册为依赖属性。这些属性允许 IconFontButton 控件根据用户交互或数据变化动态地改变其外观。

代码实现如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;namespace CustomControlLib.Buttons
{public class IconFontButton : Button{public static readonly DependencyProperty PressedBackgroundProperty =DependencyProperty.Register("PressedBackground", typeof(Brush), typeof(IconFontButton), new PropertyMetadata(Brushes.DarkBlue));/// <summary>/// 鼠标按下背景样式/// </summary>public Brush PressedBackground{get { return (Brush)GetValue(PressedBackgroundProperty); }set { SetValue(PressedBackgroundProperty, value); }}public static readonly DependencyProperty PressedForegroundProperty =DependencyProperty.Register("PressedForeground", typeof(Brush), typeof(IconFontButton), new PropertyMetadata(Brushes.White));/// <summary>/// 鼠标按下前景样式(图标、文字)/// </summary>public Brush PressedForeground{get { return (Brush)GetValue(PressedForegroundProperty); }set { SetValue(PressedForegroundProperty, value); }}public static readonly DependencyProperty MouseOverBackgroundProperty =DependencyProperty.Register("MouseOverBackground", typeof(Brush), typeof(IconFontButton), new PropertyMetadata(Brushes.RoyalBlue));/// <summary>/// 鼠标进入背景样式/// </summary>public Brush MouseOverBackground{get { return (Brush)GetValue(MouseOverBackgroundProperty); }set { SetValue(MouseOverBackgroundProperty, value); }}public static readonly DependencyProperty MouseOverForegroundProperty =DependencyProperty.Register("MouseOverForeground", typeof(Brush), typeof(IconFontButton), new PropertyMetadata(Brushes.White));/// <summary>/// 鼠标进入前景样式/// </summary>public Brush MouseOverForeground{get { return (Brush)GetValue(MouseOverForegroundProperty); }set { SetValue(MouseOverForegroundProperty, value); }}public static readonly DependencyProperty FIconProperty =DependencyProperty.Register("FIcon", typeof(string), typeof(IconFontButton), new PropertyMetadata("\ue604"));/// <summary>/// 按钮字体图标编码/// </summary>public string FIcon{get { return (string)GetValue(FIconProperty); }set { SetValue(FIconProperty, value); }}public static readonly DependencyProperty FIconSizeProperty =DependencyProperty.Register("FIconSize", typeof(int), typeof(IconFontButton), new PropertyMetadata(20));/// <summary>/// 按钮字体图标大小/// </summary>public int FIconSize{get { return (int)GetValue(FIconSizeProperty); }set { SetValue(FIconSizeProperty, value); }}public static readonly DependencyProperty FIconMarginProperty = DependencyProperty.Register("FIconMargin", typeof(Thickness), typeof(IconFontButton), new PropertyMetadata(new Thickness(0, 1, 3, 1)));/// <summary>/// 字体图标间距/// </summary>public Thickness FIconMargin{get { return (Thickness)GetValue(FIconMarginProperty); }set { SetValue(FIconMarginProperty, value); }}public static readonly DependencyProperty AllowsAnimationProperty = DependencyProperty.Register("AllowsAnimation", typeof(bool), typeof(IconFontButton), new PropertyMetadata(true));/// <summary>/// 是否启用Ficon动画/// </summary>public bool AllowsAnimation{get { return (bool)GetValue(AllowsAnimationProperty); }set { SetValue(AllowsAnimationProperty, value); }}public static readonly DependencyProperty CornerRadiusProperty =DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(IconFontButton), new PropertyMetadata(new CornerRadius(2)));/// <summary>/// 按钮圆角大小,左上,右上,右下,左下/// </summary>public CornerRadius CornerRadius{get { return (CornerRadius)GetValue(CornerRadiusProperty); }set { SetValue(CornerRadiusProperty, value); }}public static readonly DependencyProperty ContentDecorationsProperty = DependencyProperty.Register("ContentDecorations", typeof(TextDecorationCollection), typeof(IconFontButton), new PropertyMetadata(null));public TextDecorationCollection ContentDecorations{get { return (TextDecorationCollection)GetValue(ContentDecorationsProperty); }set { SetValue(ContentDecorationsProperty, value); }}static IconFontButton(){DefaultStyleKeyProperty.OverrideMetadata(typeof(IconFontButton), new FrameworkPropertyMetadata(typeof(IconFontButton)));}}
}

4、按钮特效样式实现

在 自定义控件的 Themes 文件夹下创建 Buttons 文件夹,主要存放各种按钮的样式,新建资源样视文件 IconFontButton.xaml ,引用按钮控件如下所示:
在这里插入图片描述
然后实现按钮特效样式,这里我把样式分成2个部分实现。

  • 1、按钮模板样式 FButton_Template
  • 2、按钮属性样式 FButtonStyle

样式代码实现如下所示:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:CustomControlLib.Buttons"><SolidColorBrush x:Key="ButtonBackground" Color="DimGray"></SolidColorBrush><SolidColorBrush x:Key="ButtonForeground" Color="White"></SolidColorBrush><!--鼠标在按钮上时按钮背景颜色--><SolidColorBrush x:Key="ButtonMouseOverBackground" Color="#93545454"></SolidColorBrush><!--鼠标在按钮上时按钮字体颜色--><SolidColorBrush x:Key="ButtonMouseOverForeground" Color="#E6E6E6"></SolidColorBrush><SolidColorBrush x:Key="ButtonPressedBackground" Color="#2F2F2F"></SolidColorBrush><SolidColorBrush x:Key="ButtonPressedForeground" Color="White"></SolidColorBrush><Style x:Key="IconFontText" TargetType="TextBlock"><Setter Property="FontFamily" Value="pack://application:,,,/CustomControlLib;component/Fonts/#iconfont"></Setter><Setter Property="Foreground" Value="White"/><Setter Property="TextAlignment" Value="Center"/><Setter Property="HorizontalAlignment" Value="Center"/><Setter Property="VerticalAlignment" Value="Center"/><Setter Property="FontSize" Value="20"/></Style><ControlTemplate x:Key="FButton_Template" TargetType="{x:Type local:IconFontButton}"><Border x:Name="border" Background="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path= Background}" Height="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Height}" CornerRadius="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=CornerRadius}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"Width="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Width}"><StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="{TemplateBinding Padding}"HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"><TextBlock x:Name="icon"  Margin="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=FIconMargin}" RenderTransformOrigin="0.5,0.5" Style="{StaticResource IconFontText}"Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path= FIcon}"FontSize="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path= FIconSize}" Foreground="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path= Foreground}"><TextBlock.RenderTransform><RotateTransform x:Name="transIcon" Angle="0"/></TextBlock.RenderTransform></TextBlock><TextBlock VerticalAlignment="Center"  x:Name="txt" TextDecorations="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ContentDecorations}" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Content}" FontSize="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=FontSize}" Foreground="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Foreground}"/></StackPanel></Border><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=MouseOverBackground}" TargetName="border" /><Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=MouseOverForeground}" TargetName="icon"/><Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=MouseOverForeground}" TargetName="txt"/></Trigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsMouseOver" Value="true"></Condition><Condition Property="AllowsAnimation" Value="true"></Condition></MultiTrigger.Conditions><MultiTrigger.EnterActions><BeginStoryboard><Storyboard><DoubleAnimation Storyboard.TargetName="transIcon" Storyboard.TargetProperty="Angle" To="180" Duration="0:0:0.2" /></Storyboard></BeginStoryboard></MultiTrigger.EnterActions><MultiTrigger.ExitActions><BeginStoryboard><Storyboard><DoubleAnimation Storyboard.TargetName="transIcon" Storyboard.TargetProperty="Angle" To="0" Duration="0:0:0.2" /></Storyboard></BeginStoryboard></MultiTrigger.ExitActions></MultiTrigger><Trigger Property="IsPressed" Value="True"><Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=PressedBackground}" TargetName="border" /><Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=PressedForeground}" TargetName="icon"/><Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=PressedForeground}" TargetName="txt"/></Trigger><Trigger Property="IsEnabled" Value="false"><Setter Property="Opacity" Value="0.5" TargetName="border"/></Trigger></ControlTemplate.Triggers></ControlTemplate><Style x:Key="FButtonStyle" TargetType="{x:Type local:IconFontButton}"><Setter Property="Background" Value="{StaticResource ButtonBackground}" /><Setter Property="Foreground" Value="{StaticResource ButtonForeground}" /><Setter Property="MouseOverBackground" Value="{StaticResource ButtonMouseOverBackground}" /><Setter Property="MouseOverForeground" Value="{StaticResource ButtonMouseOverForeground}" /><Setter Property="PressedBackground" Value="{StaticResource ButtonPressedBackground}" /><Setter Property="PressedForeground" Value="{StaticResource ButtonPressedForeground}" /><Setter Property="HorizontalContentAlignment" Value="Center" /><Setter Property="Width" Value="100" /><Setter Property="Height" Value="30" /><Setter Property="FontSize" Value="13" /><Setter Property="CornerRadius" Value="0" /><Setter Property="FIconSize" Value="20" /><Setter Property="Template" Value="{StaticResource FButton_Template}"/><Setter Property="Padding" Value="3,1,3,1" /><Setter Property="Content" Value="{x:Null}" /><Setter Property="FIconMargin" Value="0,0,5,0" /><Setter Property="AllowsAnimation" Value="False" /></Style><Style TargetType="{x:Type local:IconFontButton}" BasedOn="{StaticResource FButtonStyle}"/>
</ResourceDictionary>

以上我们就实现了BC 类的按钮功能,接下来我们逐个使用写出案例。

3、按钮案例演示

1、页面实现与文件创建

打开 Wpf_Examples 项目,在 ViewModels 下创建 ButtonViewModel.cs 文件,Views 文件下创建 ButtonWindow.xaml 窗体。创建完成后如下所示:

在这里插入图片描述
ButtonWindow.xaml 代码实现如下:

<Window x:Class="Wpf_Examples.Views.ButtonWindow"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_Examples.Views"xmlns:cc="clr-namespace:CustomControlLib.Buttons;assembly=CustomControlLib"DataContext="{Binding Source={StaticResource Locator},Path=FButton}"mc:Ignorable="d"Title="ButtonWindow" Height="450" Width="800" Background="#2B2B2B"><Grid><Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions><StackPanel Orientation="Horizontal"><GroupBox Header="【纯图片按钮】根据操作改变颜色" Foreground="White"><StackPanel Orientation="Vertical"><cc:IconFontButton FIcon="&#xe656;" Margin="5" AllowsAnimation="False" Foreground="Red"/><cc:IconFontButton Content="文字按钮" FIcon="" Background="Transparent" AllowsAnimation="True" Foreground="#7ACDE9"/><StackPanel Orientation="Horizontal"><cc:IconFontButton ToolTip="结束" FIcon="&#xe71e;" Foreground="Red" Margin="5,0,0,0" CornerRadius="16,0,0,16" AllowsAnimation="True"/><cc:IconFontButton ToolTip="播放" FIcon="&#xe667;" Margin="1,0,0,0" CornerRadius="0" AllowsAnimation="True" Command="{Binding ButtonClickCmd}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=ToolTip}"/><cc:IconFontButton ToolTip="暂停" FIcon="&#xe87a;" Foreground="Black" Margin="1,0,0,0" CornerRadius="0,16,16,0" AllowsAnimation="True"/></StackPanel></StackPanel></GroupBox><GroupBox Header="【文字图片按钮】图左字右 图片旋转或者字体变色" Foreground="White"><StackPanel Orientation="Vertical"><cc:IconFontButton FIcon="&#xed1f;" Foreground="#16D166" AllowsAnimation="True"  Content="有动画" /><cc:IconFontButton FIcon="&#xe660;" Foreground="#FE0000" Margin="0 8 0 0" Content="无动画" /><StackPanel Orientation="Horizontal" Margin="0 8 0 0"><cc:IconFontButton ToolTip="咨询" FIcon="&#xe658;" Content="Question" Margin="0 0 1 0"/><cc:IconFontButton ToolTip="警告" FIcon="&#xe66b;" Foreground="Yellow" Content="Wariing" Margin="0 0 1 0"/><cc:IconFontButton ToolTip="错误" FIcon="&#xe668;" Foreground="red" AllowsAnimation="True" Content="Error" Command="{Binding ButtonClickCmd}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=ToolTip}"/></StackPanel></StackPanel></GroupBox></StackPanel></Grid>
</Window>

ButtonViewModel.cs 代码实现如下:

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Wpf_Examples.Views;namespace Wpf_Examples.ViewModels
{public class ButtonViewModel:ObservableObject{public RelayCommand<string> ButtonClickCmd { get; set; }public ButtonViewModel() {ButtonClickCmd = new RelayCommand<string>(BtnFun);}private void BtnFun(string obj){switch (obj){case "播放":MessageBox.Show("播放按钮是假的,不能播放,哈哈哈哈.....","提示",MessageBoxButton.OK);break;case "错误":MessageBox.Show("系统报错了,别怕,假的啦,哈哈哈哈.....", "提示", MessageBoxButton.OK);break;}}}
}

2、依赖注入

在 ViewModelLocator 文件中实现 按钮界面 与 ViewModel 前后端的绑定,代码如下

using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;namespace Wpf_Examples.ViewModels
{public class ViewModelLocator{public IServiceProvider Services { get; }public ViewModelLocator(){Services = ConfigureServices();}private static IServiceProvider ConfigureServices(){var services = new ServiceCollection();//这里实现所有viewModel的容器注入services.AddSingleton<MainViewModel>();services.AddTransient<ButtonViewModel>();//添加其他 viewModelreturn services.BuildServiceProvider();}public MainViewModel Main => Services.GetService<MainViewModel>();public ButtonViewModel FButton => Services.GetService<ButtonViewModel>();}
}

3 运行效果

在这里插入图片描述

4、源代码下载

CSDN源代码下载链接 自定义字体图标按钮

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/59465.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《Qwen2-VL》论文精读【下】:发表于2024年10月 Qwen2-VL 迅速崛起 | 性能与GPT-4o和Claude3.5相当

1 前言 《Qwen2-VL》论文精读【上】&#xff1a;发表于2024年10月 Qwen2-VL 迅速崛起 | 性能与GPT-4o和Claude3.5相当 上回详细分析了Qwen2-VL的论文摘要、引言、实验&#xff0c;下面继续精读Qwen2-VL的方法部分。 文章目录 1 前言2 方法2.1 Model Architecture2.2 改进措施2…

TypeScript延迟执行工具类

TypeScript延迟执行工具类 在前端开发中&#xff0c;我们经常需要处理一些延迟执行、防抖和节流的场景。今天介绍一个实用的Delay工具类&#xff0c;它提供了这些常用的延迟执行功能。 文章目录 TypeScript延迟执行工具类0、完整代码1. 基础延迟执行sleep方法execute方法 2. 防…

RustRover加载Rust项目报错

问题描述&#xff1a; 昨天还可以正常使用的RustRover今天打开Rust项目一直报错&#xff1a; warning: spurious network error (3 tries remaining): [7] Couldnt connect to server (Failed to connect to 127.0.0.1 port 51342 after 105750 ms: Couldnt connect to server…

C语言---文件操作万字详细分析(6)

文件操作 到这里&#xff0c; C语言所有知识点&#xff0c; 就告已段落了&#xff0c; 虽然知识点到这里结束了&#xff0c; 但我想&#xff0c; 我们的编程之路也可能刚刚开始&#xff0c; 这些知识&#xff0c; 是我们在创造伟大事物时&#xff0c; 必不可少的基础&#xff…

回溯——3、5升杯倒4升水

回溯应用 接前面书上说数学浅谈最大公约数g c d ( a , b ) = x ∗ a + y ∗ b gcd(a,b)=x*a+y*b gcd(a,b)=x∗a+y∗bP 3 2 = 6 P_{3}^{2}=6 P32​=6只要一杯8升水代码一般回溯方法的程序结构打印接前面 递归的改造——间隔挑硬币打印所挑选的硬币需要用到回溯。但书上的回溯没…

clickhouse 安装配置

1.clickhouse官网下载安装包&#xff1a; 官网下载地址&#xff1a; https://packages.clickhouse.com/tgz/ 下载四个tgz文件&#xff1a; 1 clickhouse-common-static 2 clickhouse-common-static-dbg 3 clickhouse-server 4 clickhouse-client 2 安装上面1到4的顺序依…

STM32学习记录---jlink使用

SEGGER J-Flash V6.82g下载程序&#xff1b; 硬件&#xff1a;ARM仿真器 swd口 过程&#xff1a; 1.打开软件&#xff0c;会提示是否打开上一次的.jflash文件&#xff1b; 2.新建工程 3.选择器件&#xff0c;找不到&#xff0c;可以找相近的或者相近的核心 4.选择完成&…

IPsec传输模式与隧道模式的深度解析及应用实例

随着网络安全威胁的日益严峻&#xff0c;IPsec作为网络层安全协议&#xff0c;其传输模式与隧道模式的选择对确保通信安全至关重要。本文旨在深入探讨这两种模式的差异&#xff0c;并通过实际案例展示其应用。 一、传输模式和隧道模式的详细描述 传输模式&#xff1a; 应用场景…

A014-基于Spring Boot的家电销售展示平台设计与实现

&#x1f64a;作者简介&#xff1a;在校研究生&#xff0c;拥有计算机专业的研究生开发团队&#xff0c;分享技术代码帮助学生学习&#xff0c;独立完成自己的网站项目。 代码可以查看文章末尾⬇️联系方式获取&#xff0c;记得注明来意哦~&#x1f339; 赠送计算机毕业设计600…

代码随想录第十六天| 513.找树左下角的值 、112. 路径总和 、113. 路径总和 II、106、从中序与后序遍历序列构造二叉树

513. 找树左下角的值 题目描述 给定一个二叉树&#xff0c;找到树的最后一行最左边的节点值。 解题思路 深度优先遍历 (DFS)&#xff1a;使用深度优先遍历来查找树的左下角值。记录最大深度&#xff1a;定义 maxDepth 变量&#xff0c;用于记录遍历时的最大深度。更新左下角…

triangle_area_calculators库发布

最近将在pip网站上发布triangle_area_calculators库&#xff08;我编写的python第三方库&#xff09; triangle_area_calculators库用于计算不同类型及不同已知量的三角形面积 在triangle_area_calculators库中&#xff0c;有一个名为TriangleAreaCalculators的类 可以通过f…

分布式数据库:核心概念、架构设计及应用实践

随着互联网和大数据技术的迅猛发展&#xff0c;传统单体数据库架构在处理大规模数据、支持高并发访问方面面临严峻挑战。分布式数据库应运而生&#xff0c;以其高可用性、扩展性和容错能力&#xff0c;逐渐成为现代化企业数据库架构的主流选择。本文将系统性地介绍分布式数据库…

2024年北京海淀区中小学生信息学竞赛校级预选赛试题

2024年北京海淀区中小学生信息学竞赛校级预选赛试题 题目总数&#xff1a;24 总分数&#xff1a;100 编程基础知识单选题 第 1 题 单选题 关于 2024年海淀区信息学竞赛的描述错误的是( ) A.报名在网上报名系统进行 B.必须经过学籍所在学校的指导教师审核 C.学校…

软件测试学习笔记丨Vue常用指令-输入绑定(v-model)

本文转自测试人社区&#xff0c;原文链接&#xff1a;https://ceshiren.com/t/topic/23461 指令 指令是将一些特殊行为应用到页面DOM元素的特殊属性 格式都是以v-开始的&#xff0c;例如&#xff1a; v-model&#xff1a;双向绑定v-if和v-else&#xff1a;元素是否存在v-sho…

PySpark 本地开发环境搭建与实践

目录 一、PySpark 本地开发环境搭建 &#xff08;一&#xff09;Windows 本地 JDK 和 Hadoop 的安装 &#xff08;二&#xff09;Windows 安装 Anaconda &#xff08;三&#xff09;Anaconda 中安装 PySpark &#xff08;四&#xff09;Pycharm 中创建工程 二、编写代码 …

解决 Spring 异步处理中的 JDK 动态代理问题及相关错误分析

解决 Spring 异步处理中的 JDK 动态代理问题及相关错误分析 遇到的问题&#xff1a; 在使用 Spring 的 Async 注解开启异步处理时&#xff0c;遇到以下错误&#xff1a; The bean ServiceImplChannel could not be injected as a com.wn.order.pay.recharge.controller.Serv…

UI自动化测试 —— CSS元素定位实践!

前言 自动化测试元素定位是指在自动化测试过程中&#xff0c;通过特定的方法或策略来准确识别和定位页面上的元素&#xff0c;以便对这些元素进行进一步的操作或断言。这些元素可以是文本框、按钮、链接、图片等HTML页面上的任何可见或不可见的组件。 在自动化测试中&#xf…

封装一个请求的hook(react函数组件)

对于后台系统&#xff0c;上面筛选&#xff0c;下面表格分页的页面&#xff0c;这个hook非常实用 omitBy方法&#xff1a;过滤不为undefined的对象属性 export const omitBy <T extends IObject, K extends keyof T>(object:T, predicate:(value:T[K]) > boolean):I…

AI大模型重塑软件开发:流程、优势、挑战与展望

&#x1f9d1; 博主简介&#xff1a;CSDN博客专家&#xff0c;历代文学网&#xff08;PC端可以访问&#xff1a;https://literature.sinhy.com/#/literature?__c1000&#xff0c;移动端可微信小程序搜索“历代文学”&#xff09;总架构师&#xff0c;15年工作经验&#xff0c;…

一篇文章教会你,Pycharm 的常用配置及快捷键~

每一位Python开发者都熟悉PyCharm这个强大的IDE&#xff0c;它提供了丰富的功能来提高编程效率。但你是否充分利用了PyCharm的所有配置和快捷键&#xff1f;今天&#xff0c;我们就来深度剖析PyCharm的常用配置和快捷键&#xff0c;让你从入门到精通&#xff0c;提升编程效率&a…