<Page
x:Class="LoginApp.MainPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:LoginApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<!--Title-->
<TextBlock Text="Login Page" Foreground="Black" FontSize="40"/>
<!--UserName-->
<TextBlock Text="UserID" Foreground="Black" FontSize="30"/>
<TextBox BorderBrush="LightGray" Name="UserName" GotFocus="UserName_GotFocus"/>
<!--Password-->
<TextBlock Foreground="Black" Text="Password" Margin="9,-7,0,0" FontSize="30"/>
<PasswordBox BorderBrush="LightGray" Name="PassWord" GotFocus="UserName_GotFocus" />
<!--Login Button-->
<Button Content="Login" Background="#FF30DABB" Name="Login" Click="Login_Click" Width="338" />
<!-- Registration Button-->
<Button Content="Registration" Background="#FF30DABB" Name="SignUp" Click="SignUp_Click" Width="338"/>
</StackPanel>
</Grid>
</Page>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
namespace LoginApp.Model
{
class LoginPage
{
public void Login_Click(object sender, RoutedEventArgs e) {
}
public void SiguUp_Click(object sender, RoutedEventArgs e) {
NavigationService.Navigate(new Uri("/Views/SignUpPage.xaml", UriKind.Relative));
}
}
}
<Page
x:Class="LoginApp.SignUpPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:LoginApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White">
<Grid Margin="10,10,-5,-10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="User Registration :" Grid.Row="0" FontSize="40" Foreground="Black"/>
<TextBlock Text="UserName" Grid.Row="1" Foreground="Black" Margin="0,25,0,0"/>
<TextBox Name="TxtUserName" BorderBrush="LightGray" Grid.Row="1" Margin="100,0,0,0" GotFocus="Txt_GotFocus"/>
<TextBlock Text="Password:" Grid.Row="2" Margin="0,25,0,0" Foreground="Black"/>
<PasswordBox Name="TxtPwd" BorderBrush="LightGray" Grid.Row="2" Margin="100,0,0,0" GotFocus="pwd_GotFocus"/>
<TextBlock Text="Address:" Grid.Row="3" Margin="0,25,0,0" Foreground="Black"/>
<TextBox Name="TxtAddr" BorderBrush="LightGray" Margin="100,0,0,0" GotFocus="Txt_GotFocus"/>
<TextBlock Text="Gender:" Grid.Row="4" Margin="0,25,0,0" Foreground="Black"/>
<RadioButton Name="GenMale" Background="LightGray" Grid.Row="4" Margin="100,0,0,0" Content="Male" Foreground="Black"/>
<RadioButton Name="GenFemale" Background="LightGray" Grid.Row="4" Margin="200,0,0,0" Content="Female" Foreground="Black"/>
<TextBlock Text="Phone No:" Grid.Row="5" Margin="0,25,0,0" Foreground="Black"/>
<TextBox Name="TxtPhNo" Grid.Row="5" Margin="100,0,0,0" Foreground="LightGray" MaxLength="10" InputScope="Digits" GotFocus="Txt_GotFocus"/>
<TextBlock Text="EmailID:" Grid.Row="6" Margin="0,25,0,0" Foreground="Black"/>
<TextBox Name="TxtEmail" Grid.Row="6" Margin="100,0,0,0" GotFocus="TxtGotFocus"/>
<Button BorderBrush="Transparent" Background="#FF30DABB" Content="Submit" Name="BtnSubmit" Click="Submit_Click" Grid.Row="7" Margin="0,25.667,0,-41.667" Width="345"/>
</Grid>
</Grid>
</Page>
using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Windows.UI.Xaml;
namespace LoginApp.Model
{
class SignUpPage
{
IsolatedStorageFile ISOFile = IsolatedStorageFile.GetUserStoreForApplication();
public void Submit_Click(object sender, RoutedEventArgs e) {
if (!Regex.IsMatch(TxtUserName.Text.Trim(), @"^[A-Za-z_][a-zA-Z0-9_\s]*$")) {
MessageBox.Show("Invalid UserName");
}
}
}
}
答案 0 :(得分:2)
如果我完全理解你的所有代码,你就会分开你的* .xaml(在/ Views中)和你的* .xaml.cs(在/ Model中)。
我建议你将.xaml和.xaml.cs放在Views中,因为* .xaml.cs不是Model而是后面的代码。模型更像是数据库的一个元素(粗略地)。
然后,您的* .xaml.cs应该实现System.Windows.Controls.Page,这是一个例子:
public partial class LoginPage : Page
也不要忘记创建构造函数(但通常如果您使用Visual Studio的文件创建者,它将为您要创建的文件创建骨架):
public LoginPage()
{
InitializeComponent();
}
最后,如果它仍然不起作用,请确保您正在使用Sebastian Schulz告诉您的正确引用。