WPF弹出自定义窗口的方法
WPF弹出自定义窗口的方法
发布时间:2016-12-28 来源:查字典编辑
摘要:本文实例讲述了WPF弹出自定义窗口的方法。分享给大家供大家参考,具体如下:测试环境:[1]VS2010SP1[2]WPF(.NETFrame...

本文实例讲述了WPF弹出自定义窗口的方法。分享给大家供大家参考,具体如下:

测试环境:

[1]VS2010SP1

[2]WPF(.NET Framework 4)项目

内容简介

WPF工程如何弹出自定义窗口

第一步:自定义个窗口

为当前项目新添个Window项,XAML部份的代码略,下面是C#部份的代码。

namespace WorkflowBuilder.MyWindows { /// <summary> /// Interaction logic for InputStringWindow.xaml /// </summary> public partial class InputStringWindow : Window { public InputStringWindow() { InitializeComponent(); //设置默认输入焦点 FocusManager.SetFocusedElement(this,tbContent); } private void button1_Click(object sender, RoutedEventArgs e) { tbContent.Text = tbContent.Text.Trim(); if (tbContent.Text.Length > 0) { Close();//关闭窗口 } else { MessageBox.Show("输入的字符串长度不能为空!"); } } } }

第二步:弹出刚才定义的窗口

InputStringWindow isw = new InputStringWindow(); isw.Title = "给新页面命名"; isw.ShowDialog();//模式,弹出! //isw.Show()//无模式,弹出!

希望本文所述对大家C#程序设计有所帮助。

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C#教程学习
热门C#教程学习
编程开发子分类