c# – 如何将数据传递到MonoTouch.Dialog的代理?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 如何将数据传递到MonoTouch.Dialog的代理?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2607字,纯文字阅读大概需要4分钟。
内容图文
给定以下代码,如何将“First Name”,“Last Name”等数据传递给我的方法BookASession.SendMessage();?
RootElement CreateBookASessionRoot()
{
return new RootElement("Book a Session") {
new Section() {
new EntryElement("First Name", "First Name", ""),
new EntryElement("Last Name", "Last Name", ""),
new EntryElement("Email", "Email", "") { KeyboardType = UIKeyboardType.EmailAddress },
new DateElement("Event Date", DateTime.Now),
new RootElement ("Type of Shoot", new RadioGroup (0)){
new Section (){
new RadioElement("Wedding"),
new RadioElement("Portrait"),
new RadioElement("Boudoir"),
new RadioElement("Other")
}
} ,
new EntryElement("Message", "Message", "")
} ,
new Section () {
new StringElement("Send", delegate { BookASession.SendMessage(); } )
}
};
}
解决方法:
我想要实现这一点的方法是保持对我的输入元素的引用.通过这种方式,我可以轻松获取其输入值,而无需搜索整个元素树.我是通过将特定屏幕的创建逻辑封装在一个单独的clase中来实现的,如下所示:
public class BookASessionScreen
{
private RootElement _root = null;
private EntryElement _firstName = null;
private EntryElement _lastName = null;
private EntryElement _email = null;
private DateElement _date = null;
private RootElement _typeOfShoot = null;
private EntryElement _message = null;
private void CreateRoot()
{
_firstName = new EntryElement("First Name", "First Name", "");
_lastName = _firstName = new EntryElement("First Name", "First Name", "");
_email = new EntryElement("Email", "Email", "") { KeyboardType = UIKeyboardType.EmailAddress };
_date = new DateElement("Event Date", DateTime.Now);
_typeOfShoot = new RootElement ("Type of Shoot", new RadioGroup (0)){
new Section () {
new RadioElement("Wedding"),
new RadioElement("Portrait"),
new RadioElement("Boudoir"),
new RadioElement("Other")
}
};
_message = new EntryElement("Message", "Message", "");
_root = new RootElement("Book a Session") {
new Section() {
_firstName,
_lastName,
_email,
_date,
_typeOfShoot,
_message
} ,
new Section () {
new StringElement("Send", delegate {
//BookASession.SendMessage(_firstName.Value, _lastName.Value, ...)
})
}
};
}
public RootElement Root
{
get {
if (_root == null) {
CreateRoot();
}
return _root;
}
}
}
此外,您可能希望通过让类公开事件来解耦表单处理逻辑,如下所示:
1 – 创建一个包含事件数据的类,扩展EventArgs:
public class BookASessionArgs : EventArgs
{
public string FirstName
{
get;
set;
}
public string LastName
{
get;
set;
}
public string Email
{
get;
set;
}
}
2 – 在BookASessionScreen中声明您的事件:
public event EventHandler BookASession;
3 – 在您的代表中触发事件
if (BookASession != null) {
BookASession(this, new BookASessionArgs() {
FirstName = _firstName.Value,
LastName = _lastName.Value
//..
});
}
内容总结
以上是互联网集市为您收集整理的c# – 如何将数据传递到MonoTouch.Dialog的代理?全部内容,希望文章能够帮你解决c# – 如何将数据传递到MonoTouch.Dialog的代理?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。