簡體   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