通用 Windows 10 个应用程序使用 Visual Studio 2015
Universal Windows 10 App Using Visual Studio 2015
我开始学习 Windows 应用程序开发,使用 Visual Studio 2015 阅读这篇文章:https://code.msdn.microsoft.com/windowsapps/Windows-Phone-Login-17725566
在我的解决方案中,我创建了两个目录,一个用于视图 (xaml),另一个用于模型 (xaml.cs)。在创建我的 xaml 文件之前,一切都很顺利。当谈到xaml.cs(假设现在我在登录页面),当我点击登录按钮时,它应该进入注册页面。
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));
}
}
}
我有 NavigationService 的问题(它说 "the name NavigationService does not exist in current context")。
我卡住的第二点是注册页面。xaml.cs。我有一个名为 txtusername
的文本框。我正在尝试向文本框添加一些文本并使用消息框:
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");
}
}
}
}
<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>
使用此代码,红线指向 TxtUserName 和 MessageBox,表示 "The name does not exist in current context"。
我在其中找到一篇文章说 "use correct reference Add Reference to PresentationFramework.dll"。我添加了一个引用并单击 Select Assemblies > Framework > 检查 PresentationFramework 组件框并单击确定。
当我到达这一点时,它显示 "No Framework assemblies were found on the machine"。
我的电脑上安装了 .NET Framework 4.5。
Uuniversal Windows 应用程序中的导航已更改。要在页面之间导航,您必须使用以下代码:
Frame.Navigate(typeof(NameOfYourPage)));
你还可以传递一些参数(需要对象类型):
Frame.Navigate(typeof(NameOfYourPage), YourClassObject));
你的情况:
public void SiguUp_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(SignUpPage)));
}
要向您的 TextBox 控件添加一些文本,您应该使用 "Text" 属性:
YourTextBox.Text = "This is sample text";
您的文本框控件必须在页面的 XAML 代码中声明:
<TextBox x:Name="YourTextBox"/>
这很奇怪,我粘贴了您的代码并启动了该应用程序,它工作正常并且我能够显示文本并且文本框可见:
private void Submit_Click(object sender, RoutedEventArgs e)
{
TxtUserName.Text = "Sample text!";
}
也许您的项目还有其他问题?
我开始学习 Windows 应用程序开发,使用 Visual Studio 2015 阅读这篇文章:https://code.msdn.microsoft.com/windowsapps/Windows-Phone-Login-17725566
在我的解决方案中,我创建了两个目录,一个用于视图 (xaml),另一个用于模型 (xaml.cs)。在创建我的 xaml 文件之前,一切都很顺利。当谈到xaml.cs(假设现在我在登录页面),当我点击登录按钮时,它应该进入注册页面。
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));
}
}
}
我有 NavigationService 的问题(它说 "the name NavigationService does not exist in current context")。
我卡住的第二点是注册页面。xaml.cs。我有一个名为 txtusername
的文本框。我正在尝试向文本框添加一些文本并使用消息框:
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");
}
}
}
}
<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>
使用此代码,红线指向 TxtUserName 和 MessageBox,表示 "The name does not exist in current context"。
我在其中找到一篇文章说 "use correct reference Add Reference to PresentationFramework.dll"。我添加了一个引用并单击 Select Assemblies > Framework > 检查 PresentationFramework 组件框并单击确定。
当我到达这一点时,它显示 "No Framework assemblies were found on the machine"。
我的电脑上安装了 .NET Framework 4.5。
Uuniversal Windows 应用程序中的导航已更改。要在页面之间导航,您必须使用以下代码:
Frame.Navigate(typeof(NameOfYourPage)));
你还可以传递一些参数(需要对象类型):
Frame.Navigate(typeof(NameOfYourPage), YourClassObject));
你的情况:
public void SiguUp_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(SignUpPage)));
}
要向您的 TextBox 控件添加一些文本,您应该使用 "Text" 属性:
YourTextBox.Text = "This is sample text";
您的文本框控件必须在页面的 XAML 代码中声明:
<TextBox x:Name="YourTextBox"/>
这很奇怪,我粘贴了您的代码并启动了该应用程序,它工作正常并且我能够显示文本并且文本框可见:
private void Submit_Click(object sender, RoutedEventArgs e)
{
TxtUserName.Text = "Sample text!";
}
也许您的项目还有其他问题?