本文實(shí)例講述了WPF彈出自定義窗口的方法。分享給大家供大家參考,具體如下:
測試環(huán)境:
[1]VS2010SP1
[2]WPF(.NET Framework 4)項(xiàng)目
內(nèi)容簡介
WPF工程如何彈出自定義窗口
第一步:自定義個窗口
為當(dāng)前項(xiàng)目新添個Window項(xiàng),XAML部份的代碼略,下面是C#部份的代碼。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
namespace WorkflowBuilder.MyWindows { /// <summary> /// Interaction logic for InputStringWindow.xaml /// </summary> public partial class InputStringWindow : Window { public InputStringWindow() { InitializeComponent(); //設(shè)置默認(rèn)輸入焦點(diǎn) FocusManager.SetFocusedElement( this ,tbContent); } private void button1_Click( object sender, RoutedEventArgs e) { tbContent.Text = tbContent.Text.Trim(); if (tbContent.Text.Length > 0) { Close(); //關(guān)閉窗口 } else { MessageBox.Show( "輸入的字符串長度不能為空!" ); } } } } |
第二步:彈出剛才定義的窗口
1
2
3
4
|
InputStringWindow isw = new InputStringWindow(); isw.Title = "給新頁面命名" ; isw.ShowDialog(); //模式,彈出! //isw.Show()//無模式,彈出! |
希望本文所述對大家C#程序設(shè)計(jì)有所幫助。