当前位置: 首页 > news >正文

WPF 自定义用户控件(Content根据加减按钮改变值)

 前端代码:

    <UserControl.Resources><Style x:Key="Num_Button_Style" TargetType="Button"><Setter Property="MinWidth" Value="30" /><Setter Property="Height" Value="35" /><Setter Property="Margin" Value="0" /><Setter Property="VerticalContentAlignment" Value="Center" /><Setter Property="HorizontalContentAlignment" Value="Center" /><Setter Property="FontSize" Value="16" /><Setter Property="Foreground" Value="White" /><Setter Property="BorderThickness" Value="0" /><Setter Property="Background" Value="#12D269" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button"><Borderx:Name="border"Background="{TemplateBinding Background}"BorderBrush="{TemplateBinding BorderBrush}"BorderThickness="{TemplateBinding BorderThickness}"SnapsToDevicePixels="True"><TextBlockHorizontalAlignment="Center"VerticalAlignment="Center"FontSize="{TemplateBinding FontSize}"Foreground="{TemplateBinding Foreground}"Text="{TemplateBinding Content}" /></Border><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="border" Property="Background" Value="#4662D9" /></Trigger><Trigger Property="IsPressed" Value="True"><Setter TargetName="border" Property="Background" Value="#4662D9" /></Trigger><Trigger Property="IsEnabled" Value="False"><Setter TargetName="border" Property="Background" Value="#7Ec0EE" /></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style><Style x:Key="btnStyle" TargetType="Button"><Setter Property="Foreground" Value="#12D269" /><Setter Property="Width" Value="20" /><Setter Property="Height" Value="35" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><BorderName="PART_Background"Background="Transparent"BorderBrush="#12D269"BorderThickness="1,1,0,1"CornerRadius="3,0,0,3"><ContentPresenterHorizontalAlignment="Center"VerticalAlignment="Center"Content="{TemplateBinding ContentControl.Content}" /></Border></ControlTemplate></Setter.Value></Setter><Style.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="FontWeight" Value="Bold" /><Setter Property="Cursor" Value="Hand" /><Setter Property="Foreground" Value="Black" /></Trigger></Style.Triggers></Style>       </UserControl.Resources><Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"><Grid.ColumnDefinitions><ColumnDefinition Width="1*" /><ColumnDefinition Width="3*" /><ColumnDefinition Width="1*" /></Grid.ColumnDefinitions><Buttonx:Name="up"Grid.Column="2"Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=UpCommand}"CommandParameter="{Binding}"Content="+"Style="{StaticResource btnStyle}"><Button.Template><ControlTemplate TargetType="{x:Type Button}"><BorderName="PART_Background"Background="Transparent"BorderBrush="#12D269"BorderThickness="0,1,1,1"CornerRadius="0,3,3,0"><ContentPresenterHorizontalAlignment="Center"VerticalAlignment="Center"Content="{TemplateBinding ContentControl.Content}" /></Border></ControlTemplate></Button.Template></Button><ButtonGrid.Column="1"MinWidth="50"Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=ConfirmCommand}"CommandParameter="{Binding}"Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"Style="{StaticResource Num_Button_Style}" /><Buttonx:Name="down"Grid.Column="0"Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=DownCommand}"CommandParameter="{Binding}"Content="-"Style="{StaticResource btnStyle}" /></Grid></UserControl>

后台注册的 属性及事件:

  public string Text {get { return  (string)GetValue(TextProperty); }set { SetValue(TextProperty, value); }} public static readonly DependencyProperty TextProperty =DependencyProperty.Register("Text", typeof(string), typeof(NumericUpDown), new PropertyMetadata(default(string)));private void Button_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e){if (e.Key == Key.Enter){e.Handled = true; // 禁用回车键}}public object CommandParameter{get{return GetValue(CommandParameterProperty);}set{SetValue(CommandParameterProperty, value);}}public static readonly DependencyProperty CommandParameterProperty =DependencyProperty.Register("CommandParemeter", typeof(object), typeof(NumericUpDown), new PropertyMetadata(default(object)));public ICommand UpCommand{get { return (ICommand)GetValue(UpCommandProperty); }set { SetValue(UpCommandProperty, value); }}public static readonly DependencyProperty UpCommandProperty =DependencyProperty.Register("UpCommand", typeof(ICommand), typeof(NumericUpDown), new PropertyMetadata(default(ICommand)));public ICommand DownCommand{get { return (ICommand)GetValue(DownCommandProperty); }set { SetValue(DownCommandProperty, value); }}public static readonly DependencyProperty DownCommandProperty =DependencyProperty.Register("DownCommand", typeof(ICommand), typeof(NumericUpDown), new PropertyMetadata(default(ICommand)));public ICommand ConfirmCommand{get { return (ICommand)GetValue(ConfirmCommandProperty); }set { SetValue(ConfirmCommandProperty, value); }}public static readonly DependencyProperty ConfirmCommandProperty =DependencyProperty.Register("ConfirmCommand", typeof(ICommand), typeof(NumericUpDown), new PropertyMetadata(default(ICommand)));

功能引用的部分:

<DataGridGrid.Column="0"Height="{Binding ElementName=DGHeight, Path=ActualHeight}"AutoGenerateColumns="False"Background="White"CanUserReorderColumns="False"CanUserResizeColumns="False"CanUserResizeRows="False"HorizontalScrollBarVisibility="Hidden"IsReadOnly="True"ItemsSource="{Binding DataGridList_BindSources, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"SelectedItem="{Binding SelectBindItem}"SelectionMode="Single"SelectionUnit="FullRow"VerticalScrollBarVisibility="Hidden"><DataGrid.ColumnHeaderStyle><Style TargetType="DataGridColumnHeader"><Setter Property="HorizontalContentAlignment" Value="Center" /><Setter Property="Background" Value="#E8e8e8" /><Setter Property="BorderThickness" Value="1,1,1,1" /><Setter Property="BorderBrush" Value="#ffffff" /><Setter Property="Height" Value="50" /></Style></DataGrid.ColumnHeaderStyle><DataGrid.Columns><DataGridTemplateColumnWidth="50*"MinWidth="50"Header="BindName"><DataGridTemplateColumn.CellTemplate><DataTemplate><Grid><TextBlockHorizontalAlignment="Center"VerticalAlignment="Center"Text="{Binding BindName}" /></Grid></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn> <DataGridTemplateColumn Width="550*" Header="Button"> <DataGridTemplateColumn.CellTemplate><DataTemplate><Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Grid Margin="0,0,10,0"><uc:NumericUpDownConfirmCommand="{Binding DataContext.NumvalueCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"DownCommand="{Binding DataContext.NumValueSubCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"IsEnabled="{Binding NumvalueBtnEnableLst, Converter={StaticResource ButtonEnable}, ConverterParameter=Numvalue_ADD, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"Text="{Binding Numvalue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"UpCommand="{Binding DataContext.NumvalueAddCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" /></Grid></Grid></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn></DataGrid.Columns></DataGrid>

相关文章:

WPF 自定义用户控件(Content根据加减按钮改变值)

前端代码&#xff1a; <UserControl.Resources><Style x:Key"Num_Button_Style" TargetType"Button"><Setter Property"MinWidth" Value"30" /><Setter Property"Height" Value"35" />&l…...

CPU、GPU、显卡

CPU VS GPUCPU&#xff08;Central Processing Unit&#xff09;&#xff0c;中央处理器GPU&#xff08;Graphics Processing Unit&#xff09;&#xff0c;图形处理单元GPU 的技术演变CUDA&#xff08;Compute Unified Device Architecture&#xff09; 显卡&#xff08;Video…...

深入理解 Django 自定义用户模型

1. 引言 Django 作为一个强大的 Web 框架&#xff0c;内置了用户认证系统。然而&#xff0c;实际项目中我们通常需要扩展用户模型&#xff0c;以满足不同的业务需求。Django 提供了继承 AbstractUser 的方式&#xff0c;让我们能够轻松地定制用户模型。本文将通过一个自定义用…...

顺序表和链表的区别

顺序表和链表的区别 不同点顺序表链表&#xff08;带头双向循环&#xff09;存储空间物理上一定连续逻辑上连续物理上不一定连续随机访问&#xff08;用下标随机访问&#xff09;支持&#xff1a;O(1)不支持&#xff1a;O(N)任意位置插入或者删除元素可能需要搬移元素&#xf…...

系分-数据库总结

历年试题2024年05月试题 BCN范式&#xff0c;模式分解&#xff0c;触发器类型2023年05月试题 NoSQL基本特点&#xff0c;NoSQL对比&#xff0c;混合数据库2022年05月试题4 两段锁&#xff0c;事务并发&#xff0c;数据一致&#xff0c;本地事务发布20…...

new Date()解析

JavaScript 中的 new Date() 构造函数用于创建一个表示日期和时间的对象。Date 对象使得你可以以多种方式获取、设置和格式化日期和时间。让我们深入解析一下 new Date() 及其用法。 创建 Date 对象 可以通过多种方式创建 Date 对象&#xff1a; 不带参数&#xff1a; let no…...

df 的各种用法 以及与du 的区别

df的用法 在 Linux 中&#xff0c;“df”&#xff08;disk free&#xff09;是一个用于显示磁盘空间使用情况的命令。 一、主要功能 它可以列出文件系统的磁盘空间使用情况&#xff0c;包括磁盘总容量、已使用空间、可用空间以及使用率等信息。 二、常见用法及参数 基本用法&a…...

2024年下半年软考准考证什么时候打印?

2024年下半年软考准考证打印入口网址如下&#xff1a; https://bm.ruankao.org.cn/sign/welcome 广东的同学特别注意&#xff1a;准考证打印截止时间是11月8号&#xff0c;也就是考试前一天。一定要提前打印准考证&#xff0c;考试当天是无法打印的。 2024年下半年软考准考证…...

企业安全运行与维护(Enterprise Security Operation and Maintenance)

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:Linux运维老纪的首页…...

每日“亿“题 东方博宜OJ 1424-自然数的分解

原题链接&#xff1a;1424 - 自然数的分解-东方博宜OJ 题目描述 给定自然数 n &#xff0c;将其拆分成若干自然数的和。输出所有解&#xff0c;每组解中数字按从小到大排列。相同数字的不同排列算一组解。 如&#xff0c;读入整数 3 &#xff0c;分解方案如下&#xff1a; …...

初识Linux · 文件(1)

目录 前言&#xff1a; 回顾语言层面的文件 理解文件的预备知识 文件和磁盘 使用和认识系统调用函数 前言&#xff1a; 本文以及下篇文章&#xff0c;揭露的都是Linux中文件的奥秘&#xff0c;对于文件来说&#xff0c;初学Linux第一节课接触的就是文件&#xff0c;对于C…...

【MYSQL】mysql约束---自增长约束(auto_increment)

1、概念 在Mysql中&#xff0c;当主键为自增长后&#xff0c;这个主键的值就不再需要用户输入数据了&#xff0c;而由数据库系统根据定义自动赋值。每增加一条记录&#xff0c;主键会自动以相同的步长进行增长。 注意&#xff1a;自增长约束通常与主键放在一起使用。 通过给…...

基于STM32设计的智能学习台灯(华为云IOT)(238)

文章目录 一、前言1.1 项目介绍【1】开发背景【2】项目实现的功能【3】项目硬件模块组成【4】ESP8266工作模式配置1.2 设计思路【1】整体设计思路【2】整体构架【3】上位机开发思路1.3 项目开发背景【1】选题的意义【2】可行性分析【3】参考文献【4】摘要1.4 开发工具的选择【1…...

网络层协议 --- IP

序言 在这篇文章中我们将介绍 IP协议&#xff0c;经过这篇文章的学习&#xff0c;我们就会了解运营商到底是如何为我们提供服务的以及平时我们所说的内网&#xff0c;公网到底又是什么&#xff0c;区别是什么&#xff1f; IP 地址的基本概念 1. IP 地址的定义 每一个设备接入…...

Java虚拟机(JVM)介绍

**Java虚拟机&#xff08;JVM&#xff09;**是Java平台的核心组件&#xff0c;它提供了一个运行时环境&#xff0c;使得Java程序可以在不同的操作系统和硬件平台上运行而无需修改。 JVM的架构 JVM主要由以下几个部分组成&#xff1a; 类加载器&#xff08;Class Loader&#xf…...

1000题-计算机网络系统概述

术语定义与其他术语的关系SDU&#xff08;服务数据单元&#xff09;相邻层间交换的数据单元&#xff0c;是服务原语的表现形式。在OSI模型中&#xff0c;SDU是某一层待传送和处理的数据单元&#xff0c;即该层接口数据的总和。 - SDU是某一层的数据集&#xff0c;准备传递给下一…...

Authentication Lab | IP Based Auth Bypass

关注这个靶场的其它相关笔记&#xff1a;Authentication Lab —— 靶场笔记合集-CSDN博客 0x01&#xff1a;IP Based Auth Bypass 前情提要 有些开发人员为了图方便&#xff0c;会给站点设置一个 IP 白名单&#xff0c;如果访问站点的用户的 IP 在白名单内&#xff0c;则允许访…...

linux中的火墙优化策略

1.火墙介绍 1. netfilter 2. iptables 3. iptables | firewalld 2.火墙管理工具切换 在rocky9 中默认使用的是 firewalld firewalld -----> iptables dnf install iptables - services - y systemctl stop firewalld systemctl disable firewalld systemctl mask fi…...

GO网络编程(三):海量用户通信系统1:登录功能初步

一、准备工作 需求分析 1)用户注册 2)用户登录 3)显示在线用户列表 4)群聊(广播) 5)点对点聊天 6)离线留言 主界面 首先&#xff0c;在项目根目录下初始化mod&#xff0c;然后按照如下结构设计目录&#xff1a; 海量用户通信系统/ ├── go.mod ├── client/ │ ├──…...

Windows安全加固详解

一、补丁管理 使用适当的命令或工具&#xff0c;检查系统中是否有未安装的更新补丁。 Systeminfo 尝试手动安装一个系统更新补丁。 • 下载适当的补丁文件。 • 打开命令提示符或PowerShell&#xff0c;并运行 wusa.exe <patch_file_name>.msu。 二、账号管…...

网络六边形受到攻击

大家读完觉得有帮助记得关注和点赞&#xff01;&#xff01;&#xff01; 抽象 现代智能交通系统 &#xff08;ITS&#xff09; 的一个关键要求是能够以安全、可靠和匿名的方式从互联车辆和移动设备收集地理参考数据。Nexagon 协议建立在 IETF 定位器/ID 分离协议 &#xff08;…...

循环冗余码校验CRC码 算法步骤+详细实例计算

通信过程&#xff1a;&#xff08;白话解释&#xff09; 我们将原始待发送的消息称为 M M M&#xff0c;依据发送接收消息双方约定的生成多项式 G ( x ) G(x) G(x)&#xff08;意思就是 G &#xff08; x ) G&#xff08;x) G&#xff08;x) 是已知的&#xff09;&#xff0…...

论文浅尝 | 基于判别指令微调生成式大语言模型的知识图谱补全方法(ISWC2024)

笔记整理&#xff1a;刘治强&#xff0c;浙江大学硕士生&#xff0c;研究方向为知识图谱表示学习&#xff0c;大语言模型 论文链接&#xff1a;http://arxiv.org/abs/2407.16127 发表会议&#xff1a;ISWC 2024 1. 动机 传统的知识图谱补全&#xff08;KGC&#xff09;模型通过…...

根据万维钢·精英日课6的内容,使用AI(2025)可以参考以下方法:

根据万维钢精英日课6的内容&#xff0c;使用AI&#xff08;2025&#xff09;可以参考以下方法&#xff1a; 四个洞见 模型已经比人聪明&#xff1a;以ChatGPT o3为代表的AI非常强大&#xff0c;能运用高级理论解释道理、引用最新学术论文&#xff0c;生成对顶尖科学家都有用的…...

【Java学习笔记】BigInteger 和 BigDecimal 类

BigInteger 和 BigDecimal 类 二者共有的常见方法 方法功能add加subtract减multiply乘divide除 注意点&#xff1a;传参类型必须是类对象 一、BigInteger 1. 作用&#xff1a;适合保存比较大的整型数 2. 使用说明 创建BigInteger对象 传入字符串 3. 代码示例 import j…...

GitHub 趋势日报 (2025年06月06日)

&#x1f4ca; 由 TrendForge 系统生成 | &#x1f310; https://trendforge.devlive.org/ &#x1f310; 本日报中的项目描述已自动翻译为中文 &#x1f4c8; 今日获星趋势图 今日获星趋势图 590 cognee 551 onlook 399 project-based-learning 348 build-your-own-x 320 ne…...

MySQL 部分重点知识篇

一、数据库对象 1. 主键 定义 &#xff1a;主键是用于唯一标识表中每一行记录的字段或字段组合。它具有唯一性和非空性特点。 作用 &#xff1a;确保数据的完整性&#xff0c;便于数据的查询和管理。 示例 &#xff1a;在学生信息表中&#xff0c;学号可以作为主键&#xff…...

android RelativeLayout布局

<?xml version"1.0" encoding"utf-8"?> <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_height"match_parent"android:gravity&…...

【安全篇】金刚不坏之身:整合 Spring Security + JWT 实现无状态认证与授权

摘要 本文是《Spring Boot 实战派》系列的第四篇。我们将直面所有 Web 应用都无法回避的核心问题&#xff1a;安全。文章将详细阐述认证&#xff08;Authentication) 与授权&#xff08;Authorization的核心概念&#xff0c;对比传统 Session-Cookie 与现代 JWT&#xff08;JS…...

云安全与网络安全:核心区别与协同作用解析

在数字化转型的浪潮中&#xff0c;云安全与网络安全作为信息安全的两大支柱&#xff0c;常被混淆但本质不同。本文将从概念、责任分工、技术手段、威胁类型等维度深入解析两者的差异&#xff0c;并探讨它们的协同作用。 一、核心区别 定义与范围 网络安全&#xff1a;聚焦于保…...