WPF弹出自定义窗口的方法
作者:kagula 时间:2023-10-18 20:52:04
本文实例讲述了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#程序设计有所帮助。
标签:WPF,窗口
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android SwipeRefreshLayout超详细讲解
2023-08-22 13:43:28
![](https://img.aspxhome.com/file/2023/7/94257_0s.gif)
一文带你了解SpringBoot中常用注解的原理和使用
2022-07-22 14:27:43
JAVA8之函数式编程Function接口用法
2022-01-04 04:03:04
![](https://img.aspxhome.com/file/2023/6/63276_0s.jpg)
Java多线程同步工具类CyclicBarrier的使用
2021-08-26 05:29:53
Java 中的 xx ≠ null 是什么新语法
2022-09-10 20:51:13
![](https://img.aspxhome.com/file/2023/1/78901_0s.png)
Android树形控件绘制方法
2022-09-05 01:50:55
![](https://img.aspxhome.com/file/2023/3/89543_0s.jpg)
DWR异常情况处理常见方法解析
2022-10-14 02:10:50
c#保存窗口位置大小操作类(序列化和文件读写功能)
2023-07-15 18:51:06
C# Console利用mspaint打开图像并保存的方法
2023-07-05 16:15:43
C#创建、部署、调用WebService图文实例详解
2022-05-03 06:35:20
![](https://img.aspxhome.com/file/2023/2/113832_0s.png)
java生成指定范围随机数的多种代码
2023-04-28 07:51:15
![](https://img.aspxhome.com/file/2023/3/60383_0s.png)
Android开发之DatePicker和TimePicker实现选择日期时间功能示例
2022-10-06 05:35:21
![](https://img.aspxhome.com/file/2023/7/106037_0s.gif)
基于C#实现XML文件读取工具类
2021-10-07 07:42:19
详解用Eclipse如何创建Web项目
2023-11-11 05:41:01
![](https://img.aspxhome.com/file/2023/3/59393_0s.png)
C#中判断、验证字符串是否为日期格式的实现代码
2021-06-05 01:57:26
推荐史上最全的IDEA好用插件
2023-02-22 21:35:04
![](https://img.aspxhome.com/file/2023/8/62378_0s.png)
Java 判断数组是否相等的方法示例
2023-09-03 10:21:13
java简单工厂模式入门
2022-12-03 04:35:24
详解Java中的线程池
2023-11-10 16:33:27
![](https://img.aspxhome.com/file/2023/9/59369_0s.png)
Java后台实现微信支付和微信退款
2023-09-06 13:44:00
![](https://img.aspxhome.com/file/2023/2/92692_0s.png)