繁体   English   中英

如果感知到某个条件,则清除 Entry.Text 值

[英]Clear the Entry.Text value when if perceive a certain condition

有没有办法可以在满足某些条件时清除 entry.text? 我想我的问题是如何捕获 Xamarin 中条目更改的文本(发件人,TextChangedEventArgs)?

private void EntryBoxBarCode_TextChanged(object sender, TextChangedEventArgs e)
{
    if (EntryBoxBarCode.Text != "")
    {
        var entry = new Entry();
        entry.Text = e.NewTextValue;
        WorkFormCheck(entry.Text);

        if (typeOfBarCode != "")
        {
            //Here is the condition where I want to clear the text
            entry.Text = "";
            EntryBoxBarCode.Focus();
        }
    }
    else
    {
        //pasing the right value of the entry, then focus to other Entry
        EntryPackCode.Focus();
    }         
}
 

xml:

<Entry Grid.Row="0" Grid.Column="1" x:Name="EntryBoxBarCode" WidthRequest="250" TextChanged="EntryBoxBarCode_TextChanged"/>

我不明白的是你为什么要在 TextChanged 的​​运行时创建一个条目? 每次您在调用此 Textchanged 事件的条目中键入文本时,它都会逐个创建条目,当您在此处创建新条目时,它不是您的 UI 上的内容,如果您希望 UI 上的条目触发这个您必须为触发条目命名,然后使用该名称检查该条目中的内容并相应更新,或者您可以使用发送者对象。

您的 XAML 将类似于:

<Entry Grid.Row="0" Grid.Column="1" x:Name="EntryBoxBarCode" WidthRequest="250" TextChanged="EntryBoxBarCode_TextChanged"/>
<Entry Grid.Row="" Grid.Column="1" x:Name="EntryPackCode" WidthRequest="250" />


private void EntryBoxBarCode_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (EntryBoxBarCode.Text != "")
        {
            WorkFormCheck(EntryBoxBarCode.Text);

            if (typeOfBarCode != "")
            {
                //Here is the condition where I want to clear the text
                EntryBoxBarCode.Text = "";
                //EntryBoxBarCode.Focus(); //not sure this is required or not since you should already have focus here.
            }
        }
        else
        {
            //passing the right value of the entry, then focus to other Entry
            EntryPackCode.Focus();
        }         
    }

祝你好运

暂无
暂无

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

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