本文實例講述了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#程序設計有所幫助。
新聞熱點
疑難解答