WPF 快捷键读写txt
因为git提交需要写这次做的,所以我想弄个东西来帮我写
WPF可以使用快捷键,快捷键主要使用InputBindings,WPF读写文件很简单
我每次都要写
第一句标题
之后就是我写的修改
然后加上我名字
加上时间
有一次我修改了函数f
删除一个函数
标题是我做了工具
我需要写:
#我做了工具
修改函数f
删除函数
林德熙 2016年3月16日 16:43:40
这样每次写都需要加# 我的名字,于是我就做了个软件
点击确定
我可以在工具.txt
我可以复制里面内容,这样可以在一个不想使用git的,直接看到每天我在做
每次按确定,我觉得还是做快捷键,做了alt+enter就是放在工具.txt
快捷键
App.xaml
<Application.Resources>
<RoutedUICommand x:Key="quedin" Text="确定"></RoutedUICommand>
</Application.Resources>
捷MainPage.xaml
使用快捷键
<Window.InputBindings>
<KeyBinding Modifiers="Alt" Key="Enter" Command="{StaticResource quedin}"></KeyBinding>
</Window.InputBindings>
我们把这个命令需要按下的键Modifiers="Alt" 如果需要按ctrl+alt可以Modifiers="Control+Alt"如
后台写快捷键使用保存
private void key(object sender, RoutedEventArgs e)
{
view.text = text.Text;
view.Storage();
}
TextBox binding是失去焦点更新,我不想去改
<Window.CommandBindings>
<CommandBinding Command="{StaticResource quedin}" Executed="key"></CommandBinding>
</Window.CommandBindings>
把文件保存
using (FileStream temp = new FileStream(file, FileMode.Append))
{
byte[] buffer = Encoding.Default.GetBytes(text);
int n = buffer.Length;
temp.Write(buffer, 0, n);
text = "";
}
我使用Depend绑定文本,因为最后的text需要在后台修改,而view绑定是viewModel,前台和后台数据变化直接,可以前台使用
#region
using System.Windows;
using System.Windows.Data;
#endregion
namespace 跨境工具箱
{
public class viewModel : DependencyObject
{
public viewModel()
{
_model = new model();
Binding bind = new Binding("text")
{
Source = _model,
Mode = BindingMode.TwoWay
};
BindingOperations.SetBinding(this, text_property, bind);
bind = new Binding("name")
{
Source = _model,
Mode = BindingMode.TwoWay
};
BindingOperations.SetBinding(this, name_property, bind);
bind = new Binding("time")
{
Source = _model,
Mode = BindingMode.TwoWay
};
BindingOperations.SetBinding(this, time_property, bind);
bind = new Binding("reminder")
{
Source = _model,
Mode = BindingMode.TwoWay
};
BindingOperations.SetBinding(this, reminder_property, bind);
bind = new Binding("file")
{
Source = _model,
Mode = BindingMode.TwoWay
};
BindingOperations.SetBinding(this, file_property, bind);
}
public static readonly DependencyProperty file_property = DependencyProperty.Register(
"file", typeof (string), typeof (viewModel), new PropertyMetadata(default(string)));
public static readonly DependencyProperty reminder_property = DependencyProperty.Register(
"reminder", typeof (string), typeof (viewModel), new PropertyMetadata(default(string)));
public static readonly DependencyProperty time_property = DependencyProperty.Register(
"time", typeof (bool), typeof (viewModel), new PropertyMetadata(default(bool)));
public static readonly DependencyProperty name_property = DependencyProperty.Register(
"name", typeof (string), typeof (viewModel), new PropertyMetadata(default(string)));
public static readonly DependencyProperty text_property = DependencyProperty.Register(
"text", typeof (string), typeof (viewModel), new PropertyMetadata(default(string)));
public string file
{
set
{
SetValue(file_property, value);
}
get
{
return (string) GetValue(file_property);
}
}
public string reminder
{
set
{
SetValue(reminder_property, value);
}
get
{
return (string) GetValue(reminder_property);
}
}
public bool time
{
set
{
SetValue(time_property, value);
}
get
{
return (bool) GetValue(time_property);
}
}
public string name
{
set
{
SetValue(name_property, value);
}
get
{
return (string) GetValue(name_property);
}
}
public string text
{
set
{
SetValue(text_property, value);
}
get
{
return (string) GetValue(text_property);
}
}
private model _model;
}
}
想要这个软件给别人用,他们可以用他们名字,可以选要不要时间
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox Text="{Binding Path=name,Mode=TwoWay}" Grid.Column="0" Margin="10,10,10,10"></TextBox>
<CheckBox Content="时间" Grid.Column="1" Margin="10,10,10,10" IsChecked="{Binding Path=time,Mode=TwoWay}"></CheckBox>
<Button Grid.Column="2" Content="确定" Margin="10,10,10,10" Click="key"></Button>
保存设置
public void storage()
{
try
{
string str = "工具箱.txt";
using (FileStream temp = new FileStream(str, FileMode.Create))
{
str = file + "\n" + name + "\n" + time;
byte[] buffer = Encoding.Default.GetBytes(str);
temp.Write(buffer, 0, buffer.Length);
}
}
catch (Exception e)
{
reminder = e.Message;
}
}
这个软件我使用在宝资通
这个月准备CVTE面试,没有时间去写博客,之前在写网络编程,现在还好多问题我在找微软写的,但是他们做的好像好多没有,我看了超神的QiniuUWP,他用的我看到是HttpWebRequest Socket现在王大神就做了局域网通信,我还在看,他写的我看不明白,不是他用的高级,是没有把心放在去看他的
WPF 快捷键读写txt的更多相关文章
- WPF 读写TxT文件
原文:WPF 读写TxT文件 文/嶽永鹏 WPF 中读取和写入TxT 是经常性的操作,本篇将从详细演示WPF如何读取和写入TxT文件. 首先,TxT文件希望逐行读取,并将每行读取到的数据作为一个数组的 ...
- [转载]C#读写txt文件的两种方法介绍
C#读写txt文件的两种方法介绍 by 大龙哥 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char ...
- C#读写txt文件的两种方法介绍
C#读写txt文件的两种方法介绍 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char数组,然后输出 ...
- java指定编码的按行读写txt文件(几种读写方式的比较)
转: java指定编码的按行读写txt文件(几种读写方式的比较) 2018年10月16日 20:40:02 Handoking 阅读数:976 版权声明:本文为博主原创文章,未经博主允许不得转载. ...
- python操作txt文件中数据教程[1]-使用python读写txt文件
python操作txt文件中数据教程[1]-使用python读写txt文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原始txt文件 程序实现后结果 程序实现 filename = '. ...
- C#读写txt文件的两种方法介绍[转]
C#读写txt文件的两种方法介绍 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char数组,然后输出 ...
- C#读写txt文件的两种方法介绍 v
C#读写txt文件的两种方法介绍 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char数组,然后输出 ...
- unity3d读写txt
http://www.cnblogs.com/sunet/p/3851353.html?utm_source=tuicool 记录一下昨天用到的技术点:基于android平台unity3d读写txt. ...
- UNICODE环境下读写txt文件操作
内容转载自http://blog.sina.com.cn/s/blog_5d2bad130100t0x9.html UNICODE环境下读写txt文件操作 (2011-07-26 17:40:05) ...
随机推荐
- 团队作业4---第一次项目冲刺(ALpha)版本 第六天
一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 a.完成所有基础功能 b.正在进行测试调试 四.困难与问题 1.测试前没有理清业务逻辑,导致前期测试深度不够: 2.在验证过去 ...
- 201521123007《Java程序设计》第14周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 2. 书面作业 1. MySQL数据库基本操作 建立数据库,将自己的姓名.学号作为一条记录插入.(截图,需出现自 ...
- 小Writeup
Misc 100 下载文件之后是一个zip压缩包.因为一开始没有给任何提示信息,题目也什么都没说,爆破了一会无果.同时不是伪加密,所以应该是明文攻击.之后官方给出提示,是一个网址. F12进入调试,发 ...
- JavaScript配合button.onclick()使用总结
Html加载顺序是从上往下加载,如果script中含有引用js脚本,则应该将此script放在head标签里面,这样可是保证此页面都可以引用js脚本内容.如果想在script中设置button.onc ...
- 随便讲讲我对于svn和git的想法
1.SVN是集中式版本管理工具,而Git是分布式版本管理工具,这是核心区别. 二者都有集中的库,只是git偏向于分布式,用户可以再自己电脑上克隆一份自己的库,即使在断网的情况下也能够查看版本,创建分支 ...
- Flex布局介绍
Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性 任何一个容器都可以指定为 Flex 布局. .box{ display: -web ...
- Python初识2
27.Python中没有{}括起来的代码块,使用pass来代替c语言中的{(无内容)}: 28.使用__name__来指示模块是如何加载的,如果是被导入的,那么__name__就是该模块的名字,如果是 ...
- 利用Docker快速创建Nginx负载均衡节点
本文版权归博客园和作者吴双本人共同所有 转载和爬虫请注明原文地址 www.cnblogs.com/tdws 一.Self-Host Kestrel 1. 在vs2017中新建dotnet core2. ...
- angular 学习笔记
每天进步一点点,学习笔记 笔记来自 angular权威指南 如果想要屏蔽浏览器对表单的默认验证行为,可以在表单元素上添加 novalidate 标记. 而按钮标签则完全忽略 hr e f 属性,并不 ...
- 分享一个图片上传插件(TP5.0)
效果预览图: 该插件主要功能是:可预览裁剪图片和保存原图片,执行裁剪图片后会删除 裁剪的原图片目录,以便减少空间.一.下载附件 地址:https://pan.baidu.com/s/1bpxZhM3 ...