Ejemplo n.º 1
0
 private void ClearMeanings()  // clear Meanings list
 {
     if (Meanings != null && Meanings.Count > 0)
     {
         Meanings.Clear();
     }
 }
Ejemplo n.º 2
0
        public MainWindowViewModel()
        {
            this.ClearSearchCommand          = new DelegateCommand(() => Keyword = string.Empty);
            this.LoadSettingCommand          = new DelegateCommand(() => LoadSetting());
            this.SaveSettingCommand          = new DelegateCommand(() => SaveSetting());
            this.TextBoxEnterKeyEventCommand = new DelegateCommand <string>(async(keyword) =>
                                                                            await Task.Run(async() =>
            {
                if (string.IsNullOrEmpty(keyword))
                {
                    return;
                }

                Result result = await GetResult(keyword);

                DispatchService.Invoke(() =>
                {
                    Meanings.Clear();

                    ScrollToTop?.Invoke();

                    if (result != null && result?.Meanings?.Count > 0)
                    {
                        Meanings.AddRange(result.Meanings);
                    }
                    else
                    {
                        meanings.Add(new Meaning {
                            Word = $"未找到 (´;ω;`)"
                        });
                    }
                });
            }));
        }