From e67c04bf82b0ae8493c8724d0212e5aa513a7b1c Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sun, 7 Jun 2020 17:56:55 +0800 Subject: [PATCH] update demo --- README.md | 1 + .../Data/Model/DemoItemModel.cs | 18 +++++- .../Resources/Themes/Styles/Style.xaml | 1 + .../UserControl/Main/LeftMainContent.xaml | 2 +- .../UserControl/Main/LeftMainContent.xaml.cs | 58 ++++++++++++++++--- 5 files changed, 70 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9a604cc7..4ffaaec8 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ yxhq AiHaibara walterlv +Luoyingliang ## Backers diff --git a/src/Shared/HandyControlDemo_Shared/Data/Model/DemoItemModel.cs b/src/Shared/HandyControlDemo_Shared/Data/Model/DemoItemModel.cs index e4c6501c..7b59ed59 100644 --- a/src/Shared/HandyControlDemo_Shared/Data/Model/DemoItemModel.cs +++ b/src/Shared/HandyControlDemo_Shared/Data/Model/DemoItemModel.cs @@ -1,6 +1,8 @@ -namespace HandyControlDemo.Data +using GalaSoft.MvvmLight; + +namespace HandyControlDemo.Data { - public class DemoItemModel + public class DemoItemModel : ObservableObject { public string Name { get; set; } @@ -9,5 +11,17 @@ public string ImageName { get; set; } public bool IsNew { get; set; } + + private bool _isVisible = true; + + public bool IsVisible + { + get => _isVisible; +#if NET40 + set => Set(nameof(IsVisible), ref _isVisible, value); +#else + set => Set(ref _isVisible, value); +#endif + } } } diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Themes/Styles/Style.xaml b/src/Shared/HandyControlDemo_Shared/Resources/Themes/Styles/Style.xaml index 432f1adf..d17b720f 100644 --- a/src/Shared/HandyControlDemo_Shared/Resources/Themes/Styles/Style.xaml +++ b/src/Shared/HandyControlDemo_Shared/Resources/Themes/Styles/Style.xaml @@ -40,6 +40,7 @@ diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml index a6bcea3a..637f5961 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml @@ -44,7 +44,7 @@ - + diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml.cs index 804ed03d..65d6519d 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml.cs +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml.cs @@ -2,8 +2,8 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; +using HandyControl.Controls; using HandyControl.Data; -using HandyControl.Tools.Extension; using HandyControlDemo.Data; using HandyControlDemo.ViewModel; @@ -15,6 +15,8 @@ namespace HandyControlDemo.UserControl /// public partial class LeftMainContent { + private string _searchKey; + public LeftMainContent() { InitializeComponent(); @@ -49,13 +51,55 @@ namespace HandyControlDemo.UserControl private void SearchBar_OnSearchStarted(object sender, FunctionEventArgs e) { - if (e.Info == null) return; - if (!(sender is FrameworkElement searchBar && searchBar.Tag is ListBox listBox)) return; - foreach (DemoItemModel item in listBox.Items) + _searchKey = e.Info; + if (string.IsNullOrEmpty(_searchKey)) { - var listBoxItem = listBox.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem; - listBoxItem?.Show(item.Name.ToLower().Contains(e.Info.ToLower()) || - item.TargetCtlName.Replace("DemoCtl", "").ToLower().Contains(e.Info.ToLower())); + foreach (var item in ViewModelLocator.Instance.Main.DemoInfoCurrent.DemoItemList) + { + item.IsVisible = true; + } + } + else + { + var key = _searchKey.ToLower(); + foreach (var item in ViewModelLocator.Instance.Main.DemoInfoCurrent.DemoItemList) + { + if (item.Name.ToLower().Contains(key)) + { + item.IsVisible = true; + } + else if(item.TargetCtlName.Replace("DemoCtl", "").ToLower().Contains(key)) + { + item.IsVisible = true; + } + else + { + var name = Properties.Langs.LangProvider.GetLang(item.Name); + if (!string.IsNullOrEmpty(name) && name.ToLower().Contains(key)) + { + item.IsVisible = true; + } + else + { + item.IsVisible = false; + } + } + } + } + } + + private void SearchBar_OnTextChanged(object sender, TextChangedEventArgs e) + { + if (e.OriginalSource is SearchBar searchBar) + { + _searchKey = searchBar.Text; + if (string.IsNullOrEmpty(_searchKey)) + { + foreach (var item in ViewModelLocator.Instance.Main.DemoInfoCurrent.DemoItemList) + { + item.IsVisible = true; + } + } } } }