如何使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有修改功能的更多相关文章

  1. WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展

    一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要是对文本 ...

  2. php大力力 [052节] php数据库页面修改功能

    php大力力 [052节] php数据库页面修改功能

  3. ajax 实现修改功能

    这段时间在做项目,发现自己忘得好快呀,幸亏有博客园帮我记着呢,整理博客园简直不要太重要了哦  因为做的是一个内部管理系统,只用了一个主页面,所有的都不允许整个网页刷新,所以我们只能用ajax 来做,当 ...

  4. JAVAEE——BOS物流项目04:学习计划、datagrid、分页查询、批量删除、修改功能

    1 学习计划 1.datagrid使用方法(重要) n 将静态HTML渲染为datagrid样式 n 发送ajax请求获取json数据创建datagrid n 使用easyUI提供的API创建data ...

  5. 【转】WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展

    一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要是对文本输入控件进行样式开发,及相关扩展功能开发,主要内容包括: 基本文 ...

  6. SpringMVC由浅入深day01_9商品修改功能开发

    9 商品修改功能开发 9.1 需求 操作流程: 1.进入商品查询列表页面 2.点击修改,进入商品修改页面,页面中显示了要修改的商品(从数据库查询) 要修改的商品从数据库查询,根据商品id(主键)查询商 ...

  7. 系统管理模块_岗位管理_改进_使用ModelDroven方案_套用美工写好的页面效果_添加功能与修改功能使用同一个页面

    改进_使用ModelDroven方案 @Controller @Scope("prototype") public class RoleAction extends ActionS ...

  8. 轻松搭建CAS 5.x系列(5)-增加密码找回和密码修改功能

    概述说明 CAS内置了密码找回和密码修改的功能: 密码找回功能是,系统会吧密码重置的连接通过邮件或短信方式发送给用户,用户点击链接后就可以重置密码,cas还支持预留密码重置的问题,只有回答对了,才可以 ...

  9. javaweb之修改功能

    数据库的修改功能,主要是通过查询,保留之前的数据,得到当前想要修改的页面,并进行修改. 一.dao层 在dao层需要添加两个fangfa,一个查询,一个修改(这是整个dao层,包括之前的增删.浏览) ...

随机推荐

  1. Operation not permitted - /usr/bin/pod

    问题描述:执行sudo gem install cocoapods, 提示出错:While executing gem ... (Errno::EPERM)     Operation not per ...

  2. EasyRTMP实现Demux解析MP4文件进行rtmp推送实现RTMP直播功能

    本文转自EasyDarwin团队Kim的博客:http://blog.csdn.net/jinlong0603/article/details/52965101 前面已经介绍过EasyRTMP,这里不 ...

  3. dataware fact 事实 不可更新 data warehousing business intelligence 优劣判据

    不可 Kimball维度建模 维度建模,而非数据建模 文本型度量是对某些事情的描述.虽然以文本方式度量事实是可行的,但是应将其放入维度表中,除非对事实表的每个行,其文本是唯一的. 数据仓库的好坏直接取 ...

  4. mybatis入门(五)

    根据用户名称模糊查询用户信息 @Test public void findUserByNameTest() throws IOException { // 通过工厂得到SqlSession SqlSe ...

  5. 2014-8-17 note

    一.方格求最短路径 二.用两种颜色去染排成一个圈的6个棋子,如果通过旋转得到则只算一种,一共有多少种染色模式 设两种颜色为黑白 全黑1种+全白1种=2 1黑5白(1种)+1白5黑(1种)=2种 2黑4 ...

  6. Protocol_ISIS

    集成ISIS协议 作者:Danbo 2015-7-5 ISIS的意思是表示中间系统,并且是为OSI无连接网络协议(OSI Conectionless Network Protocol,CLNP)设计的 ...

  7. Docker容器的网络连接:

    yw1989@ubuntu:~$ ifconfig docker0 Link encap:Ethernet HWaddr 02:42:97:61:42:9f inet addr:172.17.0.1 ...

  8. hdu-5748 Bellovin(LIS)

    题目链接: Bellovin Time Limit: 6000/3000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others ...

  9. Python: PS 滤镜--USM 锐化

    本文用 Python 实现 PS 滤镜中的 USM 锐化效果,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...

  10. 洛谷 P4245 [模板]任意模数NTT —— 三模数NTT / 拆系数FFT(MTT)

    题目:https://www.luogu.org/problemnew/show/P4245 用三模数NTT做,需要注意时间和细节: 注意各种地方要取模!传入 upt() 里面的数一定要不超过2倍 m ...