Skip to content

Commit

Permalink
add a search box to the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
yanjinhuagood committed May 27, 2024
1 parent 71311fc commit 99f7304
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 22 deletions.
28 changes: 24 additions & 4 deletions src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:example="clr-namespace:WPFDevelopers.Samples.ExampleViews"
xmlns:helpers="clr-namespace:WPFDevelopers.Samples.Helpers"
Expand Down Expand Up @@ -63,15 +64,34 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border Margin="0,0,5,0" Background="{DynamicResource WD.BackgroundSolidColorBrush}">
<wd:NavigateMenu x:Name="NavigateMenu" ItemsSource="{Binding NavigateMenuModelList}">
<Grid Margin="0,0,3,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox
Name="PART_MenuTextBox"
wd:ElementHelper.IsClear="True"
wd:ElementHelper.Watermark="Please input">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<i:InvokeCommandAction Command="{Binding MenuSearchTextChanged}" CommandParameter="{Binding ElementName=PART_MenuTextBox, Path=Text}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
<controls:NavigateMenu
x:Name="NavigateMenu"
Grid.Row="1"
Margin="0,3,0,0"
DisplayMemberPath="Name"
ItemsSource="{Binding NavigateMenuModelList}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding MenuSelectionChangedCommand}" CommandParameter="{Binding ElementName=NavigateMenu, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</wd:NavigateMenu>
</Border>
</controls:NavigateMenu>
</Grid>
<GridSplitter
Grid.Column="1"
Width="5"
Expand Down
61 changes: 43 additions & 18 deletions src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using Microsoft.Expression.Drawing.Core;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -18,11 +21,11 @@

namespace WPFDevelopers.Samples.ViewModels
{
public class MainVM:ViewModelBase
public class MainVM : ViewModelBase
{
private ObservableCollection<ListBoxItem> _navigateMenuModelList;
private IList<NavigateMenuModel> _navigateMenuModelList;

public ObservableCollection<ListBoxItem> NavigateMenuModelList
public IList<NavigateMenuModel> NavigateMenuModelList
{
get { return _navigateMenuModelList; }
set { _navigateMenuModelList = value; }
Expand All @@ -38,7 +41,7 @@ public NavigateMenuModel NavigateMenuItem
set
{
_navigateMenuItem = value;
this.NotifyPropertyChange("NavigateMenuItem");
NotifyPropertyChange("NavigateMenuItem");
}
}
private object _controlPanel;
Expand All @@ -51,32 +54,54 @@ public object ControlPanel
set
{
_controlPanel = value;
this.NotifyPropertyChange("ControlPanel");
NotifyPropertyChange("ControlPanel");
}
}
public MainVM()
{
NavigateMenuModelList = new ObservableCollection<ListBoxItem>();
NavigateMenuModelList = new ObservableCollection<NavigateMenuModel>();
foreach (MenuEnum menuEnum in Enum.GetValues(typeof(MenuEnum)))
{
NavigateMenuModelList.Add(new ListBoxItem { Content = menuEnum.ToString() });
NavigateMenuModelList.Add(new NavigateMenuModel { Name = menuEnum.ToString() });
}
NavigateMenuModelList.Add(new ListBoxItem { Content = "持续更新中" });
NavigateMenuModelList.Add(new NavigateMenuModel { Name = "持续更新中" });
ControlPanel = new AnimationNavigationBar3DExample();
}

public ICommand ViewLoaded => new RelayCommand(obj =>
{


});

public ICommand MenuSearchTextChanged => new RelayCommand(obj =>
{
var search = obj.ToString();
if (string.IsNullOrEmpty(search))
{
NavigateMenuModelList.ForEach(y => y.IsVisible = true);
}
else
{
var key = search.ToLower();
foreach (var item in NavigateMenuModelList)
{
if (item.Name.ToLower().Contains(key))
item.IsVisible = true;
else
item.IsVisible = false;
}
}
});

public ICommand MenuSelectionChangedCommand => new RelayCommand(obj =>
{
if (obj == null) return;
var model = obj as ListBoxItem;
MenuItemSelection(model.Content.ToString());
var model = obj as NavigateMenuModel;
MenuItemSelection(model.Name);
});

public ICommand CloseCommand => new RelayCommand( obj =>
public ICommand CloseCommand => new RelayCommand(obj =>
{
Application.Current.MainWindow.Close();
});
Expand All @@ -87,7 +112,7 @@ void MenuItemSelection(string _menuName)
MenuEnum flag;
if (!Enum.TryParse<MenuEnum>(_menuName, true, out flag))
return;
var menuEnum = (MenuEnum)Enum.Parse(typeof(MenuEnum), _menuName,true);
var menuEnum = (MenuEnum)Enum.Parse(typeof(MenuEnum), _menuName, true);
switch (menuEnum)
{
case MenuEnum.Navigation3D:
Expand Down Expand Up @@ -138,7 +163,7 @@ void MenuItemSelection(string _menuName)
case MenuEnum.BreatheLight:
ControlPanel = new BreatheLightExample();
break;

case MenuEnum.ChatEmoji:
ControlPanel = new ChatEmojiExample();
break;
Expand Down Expand Up @@ -184,8 +209,8 @@ void MenuItemSelection(string _menuName)
case MenuEnum.DrawerMenu:
ControlPanel = new DrawerMenuExample();
break;
case MenuEnum.RadarChart:
ControlPanel = new RadarChartExample();
case MenuEnum.ChartRadar:
ControlPanel = new ChartRadarExample();
break;
case MenuEnum.LoginWindow:
ControlPanel = new LoginExample();
Expand Down Expand Up @@ -345,5 +370,5 @@ void MenuItemSelection(string _menuName)



}
}
}

0 comments on commit 99f7304

Please sign in to comment.