因为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 + " " + name + " " + time;
byte[] buffer = Encoding.Default.GetBytes(str);
temp.Write(buffer, 0, buffer.Length);
}
}
catch (Exception e)
{
reminder = e.Message;
}
}
这个软件我使用在宝资通
这个月准备CVTE面试,没有时间去写博客,之前在写网络编程,现在还好多问题我在找微软写的,但是他们做的好像好多没有,我看了超神的QiniuUWP,他用的我看到是HttpWebRequest Socket现在王大神就做了局域网通信,我还在看,他写的我看不明白,不是他用的高级,是没有把心放在去看他的