update demo

This commit is contained in:
NaBian committed 2020-06-07 17:56:55 +08:00
1 parent ea9d6b78cc
commit e67c04bf82
5 files changed
+70 -10

No files matched your search

@@ -44,7 +44,7 @@
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<hc:SearchBar SearchStarted="SearchBar_OnSearchStarted" Style="{StaticResource SearchBarPlus}" hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterKey}}" Margin="0,4,4,4" Tag="{Binding ElementName=ListBoxDemo}"/>
<hc:SearchBar ShowClearButton="True" TextChanged="SearchBar_OnTextChanged" SearchStarted="SearchBar_OnSearchStarted" Style="{StaticResource SearchBarPlus}" hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterKey}}" Margin="0,4,4,4" Tag="{Binding ElementName=ListBoxDemo}"/>
<ToggleButton Tag="{Binding ElementName=ListBoxDemo}" Name="ButtonStyleAscending" Click="ButtonAscending_OnClick" Grid.Row="0" Grid.Column="1" Style="{StaticResource DemoInfoSortButtonStyle}"/>
<ListBox Name="ListBoxDemo" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" VirtualizingStackPanel.IsVirtualizing="True" SelectedIndex="{Binding SelectedIndex}" ItemsSource="{Binding DemoItemList}" BorderThickness="0" SelectionMode="Single" Style="{StaticResource ListBoxTransparent}">
<ListBox.ItemTemplate>
@@ -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
/// </summary>
public partial class LeftMainContent
{
private string _searchKey;
public LeftMainContent()
{
InitializeComponent();
@@ -49,13 +51,55 @@ namespace HandyControlDemo.UserControl
private void SearchBar_OnSearchStarted(object sender, FunctionEventArgs<string> 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;
}
}
}
}
}