2013-07-05 48 views
2

我有一個只有一個按鈕的MainWindow,我該如何鏈接到用戶控制頁面(home.xaml)?我在主窗口是新來WPF :c#WPF按鈕鏈接到用戶控制頁面

<Button Height="100" Name="btnHome" Width="103" Click="btnHome_Click"/> 
在我mainwindow.cs

private void btnHome_Click(object sender, RoutedEventArgs e) 
    { 
     var home = new home(); 
     home.Show(); 
    } 

,但它不工作。 home.xaml是我想通過點擊mainwindow中的按鈕鏈接到的用戶控制頁面。

回答

2

您應該能夠使用NavigationService WPF頁面間導航

例子:

private void btnHome_Click(object sender, RoutedEventArgs e) 
{ 
    NavigationService.GetNavigationService(this).Navigate("home.xaml"); 
} 
+0

嗨感謝您的回覆,但他們的一個錯誤,說theres沒有NavigationService的定義,我試過了:using System.Windows.Navigation.NavigationServi CE;但錯誤仍然存​​在 – user2376998

+0

我已添加一個編輯,可能工作:) –

+0

謝謝你的時間 – user2376998

0
<asp:TextBox ID="txtName" runat="server"></asp:TextBox> 
    <br /> 
<asp:Button ID="Button1" runat="server" Text="Next" onclick="Button1_Click" /> 
Page1.aspx.cs 

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!Page.IsPostBack) 
     { 
      if (Session["Name"] != null) 
       txtName.Text = Session["Name"].ToString(); 
     } 
    } 

    protected void Button1_Click(object sender, EventArgs e) 
    { 
     Session["Name"] = txtName.Text; 
     Response.Redirect("Page2.aspx"); 
    } 
Page2.aspx 

<asp:Button ID="Button1" runat="server" Text="Back" onclick="Button1_Click" /> 
Page2.aspx.cs 

protected void Button1_Click(object sender, EventArgs e) 
    { 
     Response.Redirect("Page1.aspx"); 
    } 
+0

不知道indroducing ASP.NET到WPF將解決這個問題: ) –

0

Window w = new Window(); w.Content = new UserControl1(); w.Show();