一.窗体居中设定
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
二. 动态更新WPF不同名字的控件Text
TextBlock bTested = this.FindName("bin" + (i).ToString() + "Tested") as TextBlock;
bTested.Text = "赋值";
三.判断字符串是否相等
string.Equals("1", res5)
四.多线程使用控件,需要使用异步操作,不然会报错
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new System.Action(() =>{
testBlock.Text = "测试测试"
}));
五.WPF中开启定时器
第一步:创建定时器对象
private DispatcherTimer timer;
void Window1_Loaded(object sender, RoutedEventArgs e)
{
try
{
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(testTempTime);
timer.Tick += timer1_Tick;
timer.Start();
}
catch
{
MessageBox.Show("错误", "ERROR");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
try {
} catch
{
}
}
第二步:在window_Load添加。
public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Window1_Loaded);
initData();
}
六.判断字符串是否是null或者为空
string.IsNullOrEmpty(p_number)
七.获取启动项目实际的路径
string appStartupPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
八.清空richtext
richLog.Document.Blocks.Clear();