我怎样才能为TextEdit
(电子邮件,密码)提供ID,并在下面的Button
中保存StackLayout
。我选择了Cross Platform App(Xamarin.Forms or Native)
来构建一个简单的xamarin应用程序。下面是MainPage.xaml
。我希望收到我的MainActivity.cs
中的电子邮件值。
<Entry Placeholder="Email Id"></Entry>
<Entry Placeholder="Password" IsPassword="True"></Entry>
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
EditText emailText;
Button savebtn;
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
您可以将x:Name
属性设置为元素,因此,在这种情况下:
<Entry x:Name="emailEntry" Placeholder="Email Id"></Entry>
<Entry x:Name="passwordEntry" Placeholder="Password" IsPassword="True"></Entry>
然后,在您的页面代码隐藏类(Page.xaml.cs
)中,您可以访问这些元素:
var emailText = emailEntry.Text;
var passwordText = passwordEntry.Text;