Replies: 2 comments 8 replies
|
@Enat0 using System.Collections.Generic;
using GalaSoft.MvvmLight;
using HandyControl.Collections;
using HandyControlDemo.Data;
using HandyControlDemo.Service;
namespace HandyControlDemo.ViewModel;
public class AutoCompleteTextBoxDemoViewModel : ViewModelBase
{
private string _searchText;
public string SearchText
{
get => _searchText;
#if NET40
set
{
Set(nameof(SearchText), ref _searchText, value);
FilterItems(value);
}
#else
set
{
Set(ref _searchText, value);
FilterItems(value);
}
#endif
}
public ManualObservableCollection<DemoDataModel> Items { get; set; } = new();
private readonly List<DemoDataModel> _dataList;
public AutoCompleteTextBoxDemoViewModel(DataService dataService)
{
_dataList = dataService.GetDemoDataList(10);
}
private void FilterItems(string key)
{
Items.CanNotify = false;
Items.Clear();
foreach (var data in _dataList)
{
if (data.Name.ToLower().Contains(key.ToLower()))
{
Items.Add(data);
}
}
Items.CanNotify = true;
}
}In your case, you just need to diynamic clear Hope it works. |
4 replies
Sorry for the later response. This part of ViewModel should inherit From now on I guess is that it should not have been implemented. Here is HandyControl's Demo: public class AutoCompleteTextBoxDemoViewModel : ViewModelBase
{
}
//
// Summary:
// A base class for the ViewModel classes in the MVVM pattern.
public abstract class ViewModelBase : ObservableObject, ICleanup
{
}
//
// Summary:
// A base class for objects of which the properties must be observable.
public class ObservableObject : INotifyPropertyChanged
{
}So, could you please post a demo about you issues. Thanks. |
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello,
How can I clear the text of AutoCompleteTextBox with MVVM?
I'm trying to clear a form if I press a button but I can't seem to empty the text..
Here's my code:
And in my model view:
All reactions