-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
| ||
using System; | ||
using System.Threading; | ||
|
||
public class TypeAssistant | ||
{ | ||
public event Action<string> Idled; | ||
string Text; | ||
Timer WaitingTimer; | ||
|
||
public TypeAssistant() | ||
{ | ||
WaitingTimer = new Timer(p => Idled(Text)); | ||
} | ||
|
||
public void TextChanged(string text) | ||
{ | ||
Text = text; | ||
WaitingTimer.Change(500, Timeout.Infinite); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,47 @@ | ||
| ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace EverythingFrontend | ||
{ | ||
class ViewModel : ViewModelBase | ||
{ | ||
public ObservableCollection<Item> Items { get; } = new ObservableCollection<Item>(); | ||
TypeAssistant TypeAssistant; | ||
|
||
public ViewModel() | ||
{ | ||
TypeAssistant = new TypeAssistant(); | ||
TypeAssistant.Idled += TypeAssistant_Idled; | ||
Task.Run(() => Update("")); | ||
} | ||
|
||
private List<Item> ItemsValue; | ||
|
||
public List<Item> Items { | ||
get => ItemsValue; | ||
set { | ||
ItemsValue = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
|
||
string SearchTextValue; | ||
|
||
public string SearchText { | ||
get => SearchTextValue; | ||
set { | ||
SearchTextValue = value; | ||
Update(); | ||
TypeAssistant.TextChanged(value); | ||
} | ||
} | ||
|
||
void Update() | ||
{ | ||
Items.Clear(); | ||
void TypeAssistant_Idled(string text) => Update(text); | ||
|
||
foreach (var item in Model.GetItems(SearchText)) | ||
Items.Add(item); | ||
void Update(string text) | ||
{ | ||
List<Item> items = Model.GetItems(text); | ||
Application.Current.Dispatcher.Invoke(() => Items = items); | ||
} | ||
} | ||
} |