![](/img/trans.png)
[英]Universal Windows Application Runtime component not resulting UserIdentity on Windows 10 using Visual Studio 2015
[英]Universal Windows 10 App Using Visual Studio 2015
我開始使用 Visual Studio 2015 學習 Windows 應用程序開發,下面這篇文章: 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 的問題(它說“當前上下文中不存在名稱 NavigationService”)。
我遇到的第二點是在注冊 Page.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,表示“該名稱在當前上下文中不存在”。
我發現一篇文章說“使用正確的引用添加對 PresentationFramework.dll 的引用”。 我添加了一個引用,然后單擊選擇程序集 > 框架 > 檢查 PresentationFramework 組件框,然后單擊確定。
當我到達這一點時,它顯示“在機器上找不到框架程序集”。
我的計算機上安裝了 .NET Framework 4.5。
通用 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";
YourTextBox 控件必須在頁面的 XAML 代碼中聲明:
<TextBox x:Name="YourTextBox"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.