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) ...
随机推荐
- 201521123107 《Java程序设计》第2周学习总结
第2周作业-Java基本语法与类库 1.本周学习总结 要点主要有: (1)String类 String类是本周的一个重点,String类的对象是不可变的,即String对象后就在内存中开辟了一个字符串 ...
- 201521123106 《Java程序设计》第8周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 2. 书面作业 本次作业题集集合 List中指定元素的删除(题目4-1 ...
- 201521123018 《Java程序设计》第4周学习总结
1. 本章学习总结 2. 书面作业 Q1.注释的应用:使用类的注释与方法的注释为前面编写的类与方法进行注释,并在Eclipse中查看.(截图) Q2.面向对象设计(大作业1-非常重要) 2.1 讲故事 ...
- 201521123036 《Java程序设计》第1周学习总结
本周学习总结 本周的课是Java的入门.了解了Java的发展过程,运用平台,可跨平台的便利性.懂得jdk,jre,jvm的概念及区别.熟悉Java开发工具,掌握java程序的编译执行的详细过程. 书面 ...
- 201521123032 《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...
- 201521123119《Java程序设计》第12周学习总结
1. 本周学习总结 Q1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doub ...
- 201521123068 《java程序设计》 第13周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 书面作业 1.网络基础 1.1 比较ping www.baidu.com与ping cec.jmu. ...
- Junit4学习(二)测试失败的情况
一,前言 首先理解: 1,测试用例不是证明你是对的,而是证明你没有错 2,测试用例用来达到想要的预期结果,但对于逻辑错误无能为力 二,两种测试失败:error And Failure 1,Failur ...
- Linux入门_2-基础命令
Linux入门-基础命令 目录 日期命令date 修改时区 日历命令cal 关机启动命令halt,reboot,poweroff whoami.who.who am i.w screen ...
- 跨浏览器的placeholder – 原生JS版
转自来源 : http://www.ifrans.cn/placehoder/ 跨浏览器的placeholder – 原生JS版 html5为input元素新增了一个属性”placeholder”,提 ...