简体   繁体   English

从XAML文本框(Login_Page.xaml)获取文本值,并将其设置为XAML文本块(Menu_Page.xaml)

[英]Get text value from XAML TextBox (Login_Page.xaml) and set to XAML TextBlock (Menu_Page.xaml)

im doing an online game for Windows 8 Modern UI. 我正在为Windows 8 Modern UI做在线游戏。 Ive got Login_Page XAML file with textboxes for Login and Password. 我已经获得了Login_Page XAML文件,其中包含用于登录和密码的文本框。 Text from Login TextBox after log in has to be displayed in another XAML file (Menu_Page.xaml) as a nickname of player and also will suggesting to server which player account it is to display other things like: Experience, Level, Game_Rank. 登录后来自登录文本框的文本必须显示在另一个XAML文件(Menu_Page.xaml)中,作为玩家的昵称,并且还将向服务器建议它将显示其他内容的玩家帐户,例如:经验,等级,Game_Rank。 Can someone help me with that? 有人可以帮我吗?

If you are only having one player on each client you could set the user class to a static class and then call that from each page. 如果每个客户端上只有一个播放器,则可以将用户类别设置为静态类别,然后从每个页面调用该类别。

eg 例如

public static class Player
{
   public static string nickname{get; set;}
   //ect
}

then when you want to use it. 然后在您要使用它时。

Player.nickname = "myname";

Have you tried creating a static class to store the shared values then accessing those values when needed. 您是否尝试过创建静态类来存储共享值,然后在需要时访问这些值。 For example, you could create a static class SharedValues with the property UserName . 例如,您可以使用属性UserName创建一个静态类SharedValues After login, set the username using SharedValues.UserName = "username" . 登录后,使用SharedValues.UserName = "username"设置用户SharedValues.UserName = "username" Then in the MenuPage , just get the username. 然后在MenuPage ,只需获取用户名。 ie this.textBlock.Text = Sharedvalues.UserName . this.textBlock.Text = Sharedvalues.UserName

SharedValues class: SharedValues类:

public class SharedValues
{
    public static string UserName { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM