自定义控件,重写 TextBox 实例
项目中可能会遇到重写控件的情况,特此记录下:
1 <Window x:Class="WpfApp6.MainWindow"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6 xmlns:local="clr-namespace:WpfApp6"
7 mc:Ignorable="d"
8 Title="MainWindow" Height="157" Width="287">
9 <Window.Resources>
10 <Style TargetType="local:CustomTextBox">
11 <Setter Property="Template">
12 <Setter.Value>
13 <ControlTemplate>
14 <Grid>
15 <Grid.ColumnDefinitions>
16 <ColumnDefinition />
17 <ColumnDefinition Width="auto" />
18 </Grid.ColumnDefinitions>
19 <TextBox VerticalContentAlignment="Center"
20 Padding="5"
21 Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Text}"/>
22 <Button x:Name="btnclear" Grid.Column="1" Width="30" Margin="3" Content="清空" />
23 </Grid>
24 </ControlTemplate>
25 </Setter.Value>
26 </Setter>
27 </Style>
28 </Window.Resources>
29 <Grid>
30 <StackPanel>
31 <local:CustomTextBox Text="852"/>
32 </StackPanel>
33 </Grid>
34 </Window>
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using System.Windows;
7 using System.Windows.Controls;
8 using System.Windows.Data;
9 using System.Windows.Documents;
10 using System.Windows.Input;
11 using System.Windows.Media;
12 using System.Windows.Media.Imaging;
13 using System.Windows.Navigation;
14 using System.Windows.Shapes;
15
16 namespace WpfApp6
17 {
18 /// <summary>
19 /// MainWindow.xaml 的交互逻辑
20 /// </summary>
21 public partial class MainWindow : Window
22 {
23 public MainWindow()
24 {
25 InitializeComponent();
26 }
27 }
28
29
30 public class CustomTextBox : TextBox
31 {
32 public override void OnApplyTemplate()
33 {
34 base.OnApplyTemplate();
35
36 var btnclear = GetTemplateChild("btnclear") as Button;
37 btnclear.Click += Btnclear_Click;
38 }
39
40 private void Btnclear_Click(object sender, RoutedEventArgs e)
41 {
42 Text = string.Empty;
43 }
44 }
45 }
自定义控件,重写 TextBox 实例的更多相关文章
- nginx的URL重写应用实例
1,NGINx的URL重写 NGINX 的URL重写模块用的比较多,主要使用的命令有if rewrite set break 2 if命令 语法如下"" 语法:if(conditi ...
- 【开源EFW框架】框架中自定义控件GridBoxCard使用实例说明
回<[开源]EFW框架系列文章索引> EFW框架源代码下载V1.3:http://pan.baidu.com/s/1c0dADO0 EFW框架实例源代码下载:http://p ...
- 自定义控件之 TextBox
//textbox typevar boxType = { WaterMarkBox: 0, ValidateBox: 1, SearchBox: 2}var textBoxObj = functio ...
- nginx url重写 rewrite实例
本文介绍下,在nginx中实现Url重写,学习rewrite的具体用法,有需要的朋友参考下吧. 原文地址:http://www.360doc.com/content/14/0202/20/142341 ...
- 重写TextBox实现显示提示信息
/// <summary> /// TextBox提示信息 /// </summary> /// <author>Tim_et</author> /// ...
- java继承-重写-super实例补充
方法重写: 是指子类根据需要父类继承来的方法进行改写,是多态机制的前奏. 重写注意点: 1.重写方法必须和被重写方法具有相同的方法名,参数列表和返回值. 2.重写方法方法不能使用比被重写方法更严格的访 ...
- 很不错的NGINX URL重写实例
转自:http://www.jbxue.com/article/2187.html 本文介绍nginx URL重写的相关知识,包括301重定向的内容等,希望对大家有所帮助. nginx rewrite ...
- Android自定义控件(状态提示图表) (转)
源:Android自定义控件(状态提示图表) 源:Android应用开发 [工匠若水 http://blog.csdn.net/yanbober 转载烦请注明出处,尊重分享成果] 1 背景 前面分析 ...
- nginx 常用的 URL 重写方法
转自:http://www.jbxue.com/article/4727.html Nginx中一些常用的URL 重写方法介绍,有需要的朋友可以参考下.url重写应该不陌生,不管是SEO URL 伪静 ...
- WPF 禁用TextBox的触摸后自动弹出虚拟键盘
前言 & 问题 如下截图,TextBox,在触摸点击后,会自动弹出windows的虚拟键盘. 如何,禁用键盘的自动弹出? 调用虚拟键盘 通过调用TapTip.exe或者osk.exe,主动弹出 ...
随机推荐
- DeepSeekV3+Roo Code,智能编码好助手
前言 硅基流动最近上线了deepseek-ai/DeepSeek-R1与deepseek-ai/DeepSeek-V3,感兴趣快来试试吧! 邀请注册得14元不过期额度:https://cloud.si ...
- manim边学边做--局部变换
本次介绍的两个用于变换的动画类:TransformMatchingShapes和TransformMatchingTex. 它们的主要特点是对一组对象或一段文本进行局部变换,适用于复杂的图形或者文本的 ...
- Q:oracle备份表语句
oracle备份还原表语句 方法1.sql语句(同一数据库服务器) 备份 create table xxx_temp as select * from xxx; 还原 truncate table x ...
- [BZOJ3159] 决战 题解
个人感觉各方面难度高于<在美妙的数学王国中畅游>,也不知道是不是求导的关系,这题 \(luogu\) 难度评级还更低.不过感觉这题作完对 \(LCT\) 理解更顺畅了. 前四个操作简单,关 ...
- Oracle DBA末日or重生?不会APEX=淘汰!
残酷现实:传统DBA正在消失 "只会调优SQL的DBA,正在沦为数据库修理工!" 掌握APEX的DBA,薪资翻3倍,秒变企业核心资产! 一.DBA的死刑通知书 1. 云+AI:直接 ...
- 批量视频剪辑软件开心版合集——CRVideoMate、固乔剪辑助手、批量剪辑大师MV批量创作大师、ai全自动剪辑
CRVideoMate(推荐) 非常好用的批量剪辑工具,如果是简单的基础处理完全是够用了. 软件的官网:http://www.cr-soft.net/crvideomate.html 如果经济允许推荐 ...
- redmine 迁移后邮箱配置
https://blog.csdn.net/love8753/article/details/126380927 步骤一 修改配置文件 步骤二 redmine 页面配置信息 步骤一 修改配置文件 打开 ...
- Vite项目入口文件
官方文档:https://cn.vitejs.dev/guide/#index-html-and-project-root
- nginx 部署vue http、https
nignx配置文件 server { listen 80; server_name your_domain.com; return 301 https://$server_name$request_u ...
- k8s:The connection to the server localhost:8080 was refused - did you specify the right host or port?
前言 k8s 集群 node节点报错:The connection to the server localhost:8080 was refused - did you specify the rig ...