首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >StyledStringElement‘点击’事件

StyledStringElement‘点击’事件
EN

Stack Overflow用户
提问于 2013-05-02 12:51:25
回答 2查看 505关注 0票数 1

所以,当用户点击“StyledStringElement”时,我试图打开一个电子邮件界面--为了做到这一点,我一直在调用被点击的事件,但是我得到了错误-

错误CS1502:`MonoTouch.Dialog.Section.Add(MonoTouch.Dialog.Element)‘的最佳重载方法匹配有一些无效的参数(CS1502)

错误CS1503:参数#1' cannot convertvoid‘表达式为`MonoTouch.Dialog.Element’(CS1503)“

我使用的代码是-

代码语言:javascript
运行
复制
        section.Add(new StyledStringElement("Contact Email",item.Email) {
            BackgroundColor=UIColor.FromRGB(71,165,209),
            TextColor=UIColor.White,
            DetailColor=UIColor.White,
        }.Tapped += delegate {
            MFMailComposeViewController email = new MFMailComposeViewController();
            this.NavigationController.PresentViewController(email,true,null);
    });

是什么导致了这个错误,我如何修复它?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-02 12:54:09

您需要分别初始化"StyledStringElement“

例如:

代码语言:javascript
运行
复制
var style = new StyledStringElement("Contact Email",item.Email) {
            BackgroundColor=UIColor.FromRGB(71,165,209),
            TextColor=UIColor.White,
            DetailColor=UIColor.White,
        };

style.Tapped += delegate {
            MFMailComposeViewController email = new MFMailComposeViewController();
            this.NavigationController.PresentViewController(email,true,null);
    };

section.Add(style);
票数 2
EN

Stack Overflow用户

发布于 2013-05-02 13:30:36

new X().SomeEvent += Handler的返回值是void,所以不能在节中添加它。

不幸的是,C#官方的**不支持在对象初始化器(Assigning events in object initializer)中分配事件,因此您也不能这样做:

代码语言:javascript
运行
复制
new X() {
    SomeEvent += Handler,
};

如果您仍然希望同时实例化和附加,您可以来的最近的是

代码语言:javascript
运行
复制
StyleStringElement style;
section.Add(style = new StyledStringElement("Contact Email",item.Email) {
        BackgroundColor=UIColor.FromRGB(71,165,209),
        TextColor=UIColor.White,
        DetailColor=UIColor.White,
    });

style.Tapped += delegate {
        MFMailComposeViewController email = new MFMailComposeViewController();
        this.NavigationController.PresentViewController(email,true,null);
};

**当我正式地说,这是因为我记得有人让它在mono c#编译器的一些分支中工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16338527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档