mirror of
https://github.com/WowUp/WowUp.git
synced 2026-04-22 15:00:38 -04:00
Remove the WPF app. Create custom search component. Add filtering to the My Addons page. Use the new component on the Get Addons page.
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using WowUp.WPF.Models.Events;
|
|
using WowUp.WPF.Utilities;
|
|
|
|
namespace WowUp.WPF.ViewModels
|
|
{
|
|
public delegate void SearchEventHandler(object sender, SearchInputEventArgs e);
|
|
|
|
public class SearchInputViewModel : BaseViewModel
|
|
{
|
|
public event SearchEventHandler TextChanged;
|
|
public event SearchEventHandler Searched;
|
|
|
|
private string _inputText;
|
|
public string InputText
|
|
{
|
|
get => _inputText;
|
|
set { SetProperty(ref _inputText, value); }
|
|
}
|
|
|
|
private bool _showIcon;
|
|
public bool ShowIcon
|
|
{
|
|
get => _showIcon;
|
|
set { SetProperty(ref _showIcon, value); }
|
|
}
|
|
|
|
public Command TextChangedCommand { get; set; }
|
|
public Command SearchCommand { get; set; }
|
|
public Command ClearCommand { get; set; }
|
|
|
|
public SearchInputViewModel()
|
|
{
|
|
InputText = string.Empty;
|
|
ShowIcon = string.IsNullOrEmpty(InputText);
|
|
TextChangedCommand = new Command((text) => OnTextChanged((string)text));
|
|
SearchCommand = new Command((text) => OnSearch((string)text));
|
|
ClearCommand = new Command((text) => OnClear());
|
|
}
|
|
|
|
private void OnClear()
|
|
{
|
|
InputText = string.Empty;
|
|
ShowIcon = string.IsNullOrEmpty(InputText);
|
|
}
|
|
|
|
private void OnTextChanged(string text)
|
|
{
|
|
ShowIcon = string.IsNullOrEmpty(text);
|
|
TextChanged?.Invoke(this, new SearchInputEventArgs(InputText));
|
|
}
|
|
|
|
private void OnSearch(string text)
|
|
{
|
|
Searched?.Invoke(this, new SearchInputEventArgs(text));
|
|
}
|
|
}
|
|
}
|