简体   繁体   English

如何区分代码中的 2 个或多个输入字段

[英]How to distinguish between 2 or more entry fields in code

Raw newbie to Xamarin here. Xamarin 的原始新手在这里。 VS 2019, C#, latest Xamarin. VS 2019,C#,最新Xamarin。 Looked everywhere but must be searching with non-relevant search terms.到处寻找,但必须使用不相关的搜索词进行搜索。

So if I have 2 or more entry fields on a Xamarin form how do I know which one caused an event like onCompleted to fire.因此,如果我在 Xamarin 表单上有 2 个或更多输入字段,我怎么知道是哪一个导致了类似 onCompleted 的事件触发。 I do not see a Name or Id property for an entry field.我没有看到输入字段的名称或 ID 属性。

Entry (and Element in general!) have an Id property that can be retrieved when you need it, to uniquely identify them. 条目(和一般的Element !)有一个Id属性,可以在需要时检索它,以唯一标识它们。

If you have an Entry myEntry , then you can identify it on your event handler as:如果您有一个Entry myEntry ,那么您可以在事件处理程序上将其标识为:

Entry myEntry = new Entry()
{
    Id = Guid.NewGuid()
};

...

void Entry_Completed (object sender, EventArgs e)
{
    var entryID = ((Entry)sender).Id; //cast sender to access the properties of the Entry
    if (entryID.ToString() == myEntry.Id.ToString())
    {
        // Do something...
    }
}

I hope that helps!我希望这会有所帮助!

Note: Not proved code!注意:未证明的代码!

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

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