如何使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层,包括之前的增删.浏览) ...
随机推荐
- shift:解决shell编程中的入渗问题
我说过了,shell是我的常规武器,目前虽然还不纯熟,但是我爱shell这门语言,在Linux下面混,总要写脚本.程序员是有基因,对编程语言是有偏好的,你让我写C代码,我会觉得很爽,会有困难,会有痛苦 ...
- 用JS写九九乘法表
本来JS部分觉得就不是很好,结果经过一个寒假,在家的日子过的太舒适,基本把学的都快忘干净了,今天老师一说九九乘法表,除了脑子里浮现出要满足的条件,其他的都不记得了,赶快整理了一下: <scrip ...
- inode ls -li 显示索引节点
ls -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and .. --a ...
- Hadoop安全
kerberos-hadoop配置常见问题汇总 注意事项 常见问题如下(其中前面两点最多): 各目录属主组属性修改. 对于hadoop,需要改为yarn:hadoop/mapred:hdoop/hdf ...
- Linux服务器Java输出文件中文乱码
使用下面语句查看编码: String encoding = System.getProperty("file.encoding");结果输出:ANSI_X3.4-1968,从而导致 ...
- ffmpeg av_interleaved_write_frame Operation not permitted
今天在使用ffmpeg时出现了Operation not permitted通过增加打印信息发现是在av_interleaved_write_frame出现的问题, 昨天还没出现这个问题,很奇怪,就把 ...
- ubuntu的ufw如何开放特定端口?
ubuntu的ufw如何开放特定端口? 1.安装 sudo apt-get install ufw 2.开启 sudo ufw enable 默认关闭外部访问 sudo ufw default den ...
- centos6.5安装jdk
1.查看Linux环境自带JDK 使用命令:# rpm -qa|grep gcj 显示内容其中包含相应信息# java-x.x.x-gcj-compat-x.x.x.x-xxjpp# java-x.x ...
- ios 使用json
1.从https://github.com/stig/json-framework/中下载json框架:json-framework 2.解压下载的包,将class文件夹下的所有文件导入到当前工程下. ...
- JavaWeb----文件的上传和下载
一.开发环境搭建 创建一个FileUploadAndDownLoad项目,加入Apache的commons-fileupload文件上传组件的相关Jar包,如下图所示: 二.实现文件上传 2.1.文件 ...