2015-02-03 1 views

답변

-1

생성자를 사용하여 전달하는 방법은 아래 코드 샘플을 참조하십시오.

public partial class Login : Window 
{ 
    public Login() 
    { 
     InitializeComponent(); 
    } 

    private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     Window1 win = new Window1(txtUsername.Text); 
     win.Show(); 
    } 
} 
<Window x:Class="DelegateComd_Learning.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="300" Width="300"> 
<Grid> 
    <TextBlock x:Name="txtDisplayUsername"/> 
</Grid> 

<Window x:Class="DelegateComd_Learning.Login" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Login" Height="300" Width="300"> 
<Grid> 
    <StackPanel> 
     <StackPanel Orientation="Horizontal"> 
      <TextBlock Text="Username"/> 
      <TextBox x:Name="txtUsername" Width="100"/> 
     </StackPanel> 
     <Button Content="Login" Click="Button_Click"/> 
    </StackPanel> 
</Grid> 

public partial class Window1 : Window 
{ 
    public Window1(string username) 
    { 
     InitializeComponent(); 
     txtDisplayUsername.Text = username; 
    } 
} 
+0

굉장! 고마워 – user3793233