Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms 在执行下拉刷新时,如何清除条目文本?_Xamarin.forms - Fatal编程技术网

Xamarin.forms 在执行下拉刷新时,如何清除条目文本?

Xamarin.forms 在执行下拉刷新时,如何清除条目文本?,xamarin.forms,Xamarin.forms,我在页面顶部有一个条目,在页面下方有一个列表视图。在进行下拉刷新时,我希望清除该条目上的文本 以下是我的入境代码: <Entry x:Name="SearchEntry" HorizontalOptions="FillAndExpand" VerticalOptions="Center" PlaceholderColor="Black" FontFamily="Bold" TextColor="Black" Placeholder=

我在页面顶部有一个条目,在页面下方有一个列表视图。在进行下拉刷新时,我希望清除该条目上的文本

以下是我的入境代码:

<Entry 
    x:Name="SearchEntry"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="Center"
    PlaceholderColor="Black"
    FontFamily="Bold"
    TextColor="Black"
    Placeholder="Search a Directory"/>


提前感谢

我假设您使用MVVM并拥有一个
视图模型

ViewModel
Entry.Text
创建并绑定字符串类型的属性。内部刷新方法将此属性设置为
null
string.Empty

例如:

class MyViewModel : INotifyPropertyChanged
{
    // TODO: Handle INotifyPropertyChanged correctly
    public string EntryTextProp { get; set; }

    public async Task<?> UpdateList()
    {
        // ...
        EntryTextProp = null;
        // ...
    }
}

<Entry 
    x:Name="SearchEntry"
    Text="{Binding EntryTextProp}"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="Center"
    PlaceholderColor="Black"
    FontFamily="Bold"
    TextColor="Black"
    Placeholder="Search a Directory"/>
类MyViewModel:INotifyPropertyChanged
{
//TODO:正确更改了句柄INotifyProperty
公共字符串EntryTextProp{get;set;}
公共异步任务更新列表()
{
// ...
EntryTextProp=null;
// ...
}
}

我假设您使用MVVM,并且有一个
ViewModel

ViewModel
Entry.Text
创建并绑定字符串类型的属性。内部刷新方法将此属性设置为
null
string.Empty

例如:

class MyViewModel : INotifyPropertyChanged
{
    // TODO: Handle INotifyPropertyChanged correctly
    public string EntryTextProp { get; set; }

    public async Task<?> UpdateList()
    {
        // ...
        EntryTextProp = null;
        // ...
    }
}

<Entry 
    x:Name="SearchEntry"
    Text="{Binding EntryTextProp}"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="Center"
    PlaceholderColor="Black"
    FontFamily="Bold"
    TextColor="Black"
    Placeholder="Search a Directory"/>
类MyViewModel:INotifyPropertyChanged
{
//TODO:正确更改了句柄INotifyProperty
公共字符串EntryTextProp{get;set;}
公共异步任务更新列表()
{
// ...
EntryTextProp=null;
// ...
}
}

在此处更新完整的代码,这可能会帮助其他人。

class MyViewModel : INotifyPropertyChanged
{
    string _entrytext = "";
    public string EntryText
    {
        protected set
        {
            if (_entrytext != value)
            {
                _entrytext = value;
                OnPropertyChanged("EntryText");
            }
        }
        get { return _entrytext; }
    }

    public ICommand RefreshCommand
    {
        get
        {
            return new Command(async () =>
            {
                IsRefreshing = true;
                EntryText = null;
                MyList();
                IsRefreshing = false;
            });
        }
    }
}



  <Entry 
    x:Name="SearchEntry"
    Text="{Binding EntryTextProp}"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="Center"
    PlaceholderColor="Black"
    FontFamily="Bold"
    TextColor="Black"
    Placeholder="Search a Directory"/>
类MyViewModel:INotifyPropertyChanged
{
字符串_entrytext=“”;
公共字符串入口文本
{
保护集
{
if(_entrytext!=值)
{
_entrytext=值;
OnPropertyChanged(“EntryText”);
}
}
获取{return\u entrytext;}
}
公共ICommand刷新命令
{
得到
{
返回新命令(异步()=>
{
IsRefreshing=真;
EntryText=null;
MyList();
IsRefreshing=假;
});
}
}
}

在此处更新完整的代码,这可能会帮助其他人。

class MyViewModel : INotifyPropertyChanged
{
    string _entrytext = "";
    public string EntryText
    {
        protected set
        {
            if (_entrytext != value)
            {
                _entrytext = value;
                OnPropertyChanged("EntryText");
            }
        }
        get { return _entrytext; }
    }

    public ICommand RefreshCommand
    {
        get
        {
            return new Command(async () =>
            {
                IsRefreshing = true;
                EntryText = null;
                MyList();
                IsRefreshing = false;
            });
        }
    }
}



  <Entry 
    x:Name="SearchEntry"
    Text="{Binding EntryTextProp}"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="Center"
    PlaceholderColor="Black"
    FontFamily="Bold"
    TextColor="Black"
    Placeholder="Search a Directory"/>
类MyViewModel:INotifyPropertyChanged
{
字符串_entrytext=“”;
公共字符串入口文本
{
保护集
{
if(_entrytext!=值)
{
_entrytext=值;
OnPropertyChanged(“EntryText”);
}
}
获取{return\u entrytext;}
}
公共ICommand刷新命令
{
得到
{
返回新命令(异步()=>
{
IsRefreshing=真;
EntryText=null;
MyList();
IsRefreshing=假;
});
}
}
}

这不起作用,我尝试了EntryTextProp=null;EntryTextProp=string.empty;和EntryTextProp=“”;从命令lambda表达式中删除async关键字,并将IsRefreshing=true;在第一行。我猜你们的评论和我的答案无关?是的,这是针对问题而不是你们的答案,对不起。这不起作用,我尝试了EntryTextProp=null;EntryTextProp=string.empty;和EntryTextProp=“”;从命令lambda表达式中删除async关键字,并将IsRefreshing=true;在第一行。我猜你们的评论和我的答案无关?对,这是针对问题而不是你们的答案,对不起。