none
如何做登陆界面,登陆成功转入主窗体?? RRS feed

答案

  • 你只要在登陆按钮的事件中写入你自己的验证逻辑,然后创建主窗体的实例,Show他并且关闭登陆窗就可以了:

    登陆窗XAML:

    <Window x:Class="WpfApplication20.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Login" Height="350" Width="525" SizeToContent="WidthAndHeight">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="auto"/>
          <RowDefinition Height="auto"/>
          <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="auto"/>
          <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
        <TextBlock Text="User Name:" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        <TextBox Text="Please enter User Name" Grid.Column="1" Margin="2" BorderBrush="Gray" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        <TextBlock Text="Password:" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        <PasswordBox Grid.Row="1" Grid.Column="1" Margin="2" BorderBrush="Gray" VerticalAlignment="Center"/>
        <Button Grid.Row="2" Grid.ColumnSpan="2" Content="Login" Click="Button_Click" HorizontalAlignment="Right" Margin="4"/>
      </Grid>
    </Window>
    
    

    登陆窗后台逻辑代码:

        private void Button_Click(object sender, RoutedEventArgs e)
        {
          // TO DO the user name and password validation....
    
          HelloWindow win = new HelloWindow();
          win.Show();
          this.Close();
        }
    


    例子下载:https://skydrive.live.com/?cid=51b2fdd068799d15#!/?cid=51b2fdd068799d15&sc=documents&uc=1&id=51B2FDD068799D15%21861

     

    Sincerely, 


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    • 已标记为答案 WCF小Q 2011年11月18日 12:33
    2011年11月18日 8:08
    版主

全部回复

  • 你只要在登陆按钮的事件中写入你自己的验证逻辑,然后创建主窗体的实例,Show他并且关闭登陆窗就可以了:

    登陆窗XAML:

    <Window x:Class="WpfApplication20.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Login" Height="350" Width="525" SizeToContent="WidthAndHeight">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="auto"/>
          <RowDefinition Height="auto"/>
          <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="auto"/>
          <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
        <TextBlock Text="User Name:" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        <TextBox Text="Please enter User Name" Grid.Column="1" Margin="2" BorderBrush="Gray" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        <TextBlock Text="Password:" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        <PasswordBox Grid.Row="1" Grid.Column="1" Margin="2" BorderBrush="Gray" VerticalAlignment="Center"/>
        <Button Grid.Row="2" Grid.ColumnSpan="2" Content="Login" Click="Button_Click" HorizontalAlignment="Right" Margin="4"/>
      </Grid>
    </Window>
    
    

    登陆窗后台逻辑代码:

        private void Button_Click(object sender, RoutedEventArgs e)
        {
          // TO DO the user name and password validation....
    
          HelloWindow win = new HelloWindow();
          win.Show();
          this.Close();
        }
    


    例子下载:https://skydrive.live.com/?cid=51b2fdd068799d15#!/?cid=51b2fdd068799d15&sc=documents&uc=1&id=51B2FDD068799D15%21861

     

    Sincerely, 


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    • 已标记为答案 WCF小Q 2011年11月18日 12:33
    2011年11月18日 8:08
    版主
  • Bob Bao  多谢~
    2011年11月18日 12:33