如何使Label有修改功能
如何使Label有修改功能
之前制作一个项目时需要这样一个功能: 双击Label, 随后Label变为TextBox,用户修改后回车,TextBox变回Label
之前使用WPF做了一个,代码如下:
#region Column Header Template
var facPanel = new FrameworkElementFactory(typeof(System.Windows.Controls.StackPanel));
#region 设置StackPanel
facPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
//facPanel.SetValue(StackPanel.BackgroundProperty, Brushes.Green);
facPanel.SetValue(StackPanel.MarginProperty, new Thickness(0, 0, 0, 0));
//facPanel.SetValue(StackPanel.HeightProperty, (double)20);
#endregion
var facLabel = new FrameworkElementFactory(typeof(Label));
var p = new Pair<Label, TextBox>(null, null);
#region 设置Label
//facLabel.SetValue(Label.ContentProperty, item.Description);
var biLabel = new Binding("Description");
biLabel.Source = item;
biLabel.Mode = BindingMode.TwoWay;
facLabel.SetValue(Label.ContentProperty, biLabel);
//facLabel.SetValue(Label.FontSizeProperty, (double)10);
//facLabel.SetValue(Label.BackgroundProperty, Brushes.Gold);
facLabel.AddHandler(Label.MouseDoubleClickEvent, new MouseButtonEventHandler((o, a) =>
{
var label = (o as Label);
if (null == label)
return;
label.Visibility = Visibility.Collapsed;
}));
facLabel.AddHandler(Label.LoadedEvent, new RoutedEventHandler((o, a) =>
{
if (!(o is Label))
return;
p.Key = o as Label;
if (null != p.Key && null != p.Value)
__SetBindInLabelAndTextBox(p.Key, p.Value);
}));
#endregion
var facTextBox = new FrameworkElementFactory(typeof(TextBox));
#region 设置TextBox
//var bTextBox = new Binding("Visibility") { Source=};
//bTextBox.Mode = BindingMode.OneWay;
facTextBox.SetValue(TextBox.VisibilityProperty, Visibility.Collapsed);
facTextBox.AddHandler(TextBox.LoadedEvent, new RoutedEventHandler((o, a) =>
{
if (!(o is TextBox))
return;
p.Value = o as TextBox;
p.Value.KeyUp += new KeyEventHandler((o2, k) =>
{
if (!(o2 is TextBox))
return;
if (k.Key != Key.Enter)
return;
if (p.Key == null)
return;
p.Key.Visibility = Visibility.Visible;
});
p.Value.LostFocus += new RoutedEventHandler((o2, r) =>
{
if (!(o2 is TextBox))
return;
if (p.Key == null)
return;
p.Key.Visibility = Visibility.Visible;
});
p.Value.IsVisibleChanged += (sender, e) =>
{
if ((bool)e.NewValue == true)
p.Value.SelectAll();
p.Value.Focus();
};
if (null != p.Key && null != p.Value)
__SetBindInLabelAndTextBox(p.Key, p.Value);
}));
#endregion
var facDelBtn = new FrameworkElementFactory(typeof(Button));
#region 设置DeleteButton
facDelBtn.SetValue(Button.WidthProperty, (double)15);
facDelBtn.SetValue(Button.HeightProperty, (double)15);
facDelBtn.SetValue(Button.FontFamilyProperty, new FontFamily("Webdings"));
facDelBtn.SetValue(Button.FontSizeProperty, (double)10);
facDelBtn.SetValue(Button.ForegroundProperty, Brushes.Red);
facDelBtn.SetValue(Button.BackgroundProperty, Brushes.Snow);
facDelBtn.SetValue(Button.ContentProperty, "r");
facDelBtn.AddHandler(Button.ClickEvent, new RoutedEventHandler((o, a) =>
{
_RemoveOutputColumnItem(column);
}));
#endregion
#region 组合各个子控件
facPanel.AppendChild(facLabel);
facPanel.AppendChild(facTextBox);
facPanel.AppendChild(facDelBtn);
#endregion
column.HeaderTemplate = new DataTemplate();
column.HeaderTemplate.VisualTree = facPanel;
#endregion
如何使Label有修改功能的更多相关文章
- WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展
一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要是对文本 ...
- php大力力 [052节] php数据库页面修改功能
php大力力 [052节] php数据库页面修改功能
- ajax 实现修改功能
这段时间在做项目,发现自己忘得好快呀,幸亏有博客园帮我记着呢,整理博客园简直不要太重要了哦 因为做的是一个内部管理系统,只用了一个主页面,所有的都不允许整个网页刷新,所以我们只能用ajax 来做,当 ...
- JAVAEE——BOS物流项目04:学习计划、datagrid、分页查询、批量删除、修改功能
1 学习计划 1.datagrid使用方法(重要) n 将静态HTML渲染为datagrid样式 n 发送ajax请求获取json数据创建datagrid n 使用easyUI提供的API创建data ...
- 【转】WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展
一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要是对文本输入控件进行样式开发,及相关扩展功能开发,主要内容包括: 基本文 ...
- SpringMVC由浅入深day01_9商品修改功能开发
9 商品修改功能开发 9.1 需求 操作流程: 1.进入商品查询列表页面 2.点击修改,进入商品修改页面,页面中显示了要修改的商品(从数据库查询) 要修改的商品从数据库查询,根据商品id(主键)查询商 ...
- 系统管理模块_岗位管理_改进_使用ModelDroven方案_套用美工写好的页面效果_添加功能与修改功能使用同一个页面
改进_使用ModelDroven方案 @Controller @Scope("prototype") public class RoleAction extends ActionS ...
- 轻松搭建CAS 5.x系列(5)-增加密码找回和密码修改功能
概述说明 CAS内置了密码找回和密码修改的功能: 密码找回功能是,系统会吧密码重置的连接通过邮件或短信方式发送给用户,用户点击链接后就可以重置密码,cas还支持预留密码重置的问题,只有回答对了,才可以 ...
- javaweb之修改功能
数据库的修改功能,主要是通过查询,保留之前的数据,得到当前想要修改的页面,并进行修改. 一.dao层 在dao层需要添加两个fangfa,一个查询,一个修改(这是整个dao层,包括之前的增删.浏览) ...
随机推荐
- Linux学习笔记--ps命令(显示当前进程的命令)
ps:英文名process,进程的意思. 1. 命令格式: ps [选项] 2. 经常使用选项: "ps -a" 显示一个终端的全部进程.除了会话引线 "ps -e&qu ...
- Java类加载器( 死磕7)
[正文]Java类加载器( CLassLoader )死磕7: 基于加密的自定义网络加载器 本小节目录 7.1. 加密传输Server端的源码 7.2. 加密传输Client端的源码 7.3. 使 ...
- virtualbox Units specified don't exist. SHSUCDX can't install.
version infomatin: virtual box: 5.1.12 platform: win10 x64 target OS: win7 x64 问题 在win10系统上,使用virtua ...
- appium(3)-Running Tests
Running Tests Preparing your app for test (iOS) Test apps run on the simulator have to be compiled ...
- hibernate双向关联
双向关联中最好的设置是一端为inverse=true,一端为inverse=false. falses维护,true不维护,设置多的一方维护(false) inverse属性就是用来规定是由谁来维护这 ...
- [haoi2008]玩具命名
某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够扩充得很 ...
- error MSB6006: “CL.exe”已退出,代码为 -1073741502。
错误1error MSB6006: “CL.exe”已退出,代码为 -1073741502.C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Plat ...
- 关于S50卡密钥A和密钥B
关于S50卡密钥A和密钥B 1. Mifare_Std 卡片的密钥属性取决于控制字.控制字的默认值是“FF078069”,此时 A密钥:不可被读出,有全部权限. B密钥:可被读出,没有任何权限. 2. ...
- hdu 1391 Number Steps(规律)
题意:找规律 思路:找规律 #include<iostream> #include<stdio.h> using namespace std; int main(){ int ...
- touch实现滑动删除
请用chrome手机模式查看或者在手机上查看(转载请注明出处) <!DOCTYPE html> <html> <head> <meta charset=&qu ...