add support for search

This commit is contained in:
NaBian committed 2019-01-17 15:00:08 +08:00
1 parent 9b827cba3c
commit d0094f049e
9 files changed
+113 -12

No files matched your search

+2 -2
View File
@@ -28,7 +28,7 @@ namespace HandyControl.Controls
{ {
RaiseEvent(new FunctionEventArgs<string>(SearchStartedEvent, this) RaiseEvent(new FunctionEventArgs<string>(SearchStartedEvent, this)
{ {
Source = Text Info = Text
}); });
})); }));
} }
@@ -72,7 +72,7 @@ namespace HandyControl.Controls
{ {
RaiseEvent(new FunctionEventArgs<string>(SearchStartedEvent, this) RaiseEvent(new FunctionEventArgs<string>(SearchStartedEvent, this)
{ {
Source = Text Info = Text
}); });
} }
} }
@@ -16,6 +16,7 @@
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/> <Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
<Setter Property="Height" Value="30"/> <Setter Property="Height" Value="30"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="BorderThickness" Value="1"/> <Setter Property="BorderThickness" Value="1"/>
<Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template"> <Setter Property="Template">
@@ -28,7 +29,7 @@
<ColumnDefinition Width="30"/> <ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="1" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/> <Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="1" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" Padding="5,6" Margin="0,0,0,1" x:Name="PART_TextBox" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> <controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" Padding="5,6" Margin="0,0,0,1" x:Name="PART_TextBox" HorizontalAlignment="Stretch" Grid.Column="0" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid> </Grid>
</Border> </Border>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
@@ -64,7 +65,7 @@
<ColumnDefinition Width="30"/> <ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="1" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/> <Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="1" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" x:Name="PART_TextBox" Padding="5,6" Margin="0,0,0,1" Watermark="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> <controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" x:Name="PART_TextBox" Padding="5,6" Margin="0,0,0,1" Watermark="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>
@@ -98,7 +99,7 @@
<ColumnDefinition Width="30"/> <ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="1" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/> <Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="1" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" x:Name="PART_TextBox" Padding="5,6" Margin="0,0,0,1" Watermark="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> <controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" x:Name="PART_TextBox" Padding="5,6" Margin="0,0,0,1" Watermark="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>
@@ -156,7 +157,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Command="interactivity:ControlCommands.Clear" Visibility="Collapsed" Name="ButtonClear" Width="16" Grid.Column="1" Style="{StaticResource ButtonIcon}" Padding="0,6" controls:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}" Foreground="{Binding BorderBrush,ElementName=templateRoot}"/> <Button Command="interactivity:ControlCommands.Clear" Visibility="Collapsed" Name="ButtonClear" Width="16" Grid.Column="1" Style="{StaticResource ButtonIcon}" Padding="0,6" controls:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}" Foreground="{Binding BorderBrush,ElementName=templateRoot}"/>
<Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="2,7,7,7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="2" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/> <Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="2,7,7,7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="2" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" x:Name="PART_TextBox" Padding="5,6" Margin="0,0,0,1" Watermark="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> <controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" x:Name="PART_TextBox" Padding="5,6" Margin="0,0,0,1" Watermark="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>
@@ -217,7 +218,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Command="interactivity:ControlCommands.Clear" Visibility="Collapsed" Name="ButtonClear" Width="16" Grid.Column="1" Style="{StaticResource ButtonIcon}" Padding="0,6" controls:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}" Foreground="{Binding BorderBrush,ElementName=templateRoot}"/> <Button Command="interactivity:ControlCommands.Clear" Visibility="Collapsed" Name="ButtonClear" Width="16" Grid.Column="1" Style="{StaticResource ButtonIcon}" Padding="0,6" controls:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}" Foreground="{Binding BorderBrush,ElementName=templateRoot}"/>
<Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="2,7,7,7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="2" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/> <Button Command="interactivity:ControlCommands.Search" Style="{StaticResource ButtonIcon}" Padding="2,7,7,7" controls:IconElement.Geometry="{StaticResource SearchGeometry}" Grid.Column="2" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" x:Name="PART_TextBox" Padding="5,6" Margin="0,0,0,1" Watermark="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> <controls:WatermarkTextBox CaretBrush="{TemplateBinding Foreground}" x:Name="PART_TextBox" Padding="5,6" Margin="0,0,0,1" Watermark="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>
+1
View File
@@ -692,6 +692,7 @@
<Generator>TextTemplatingFileGenerator</Generator> <Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MessageToken.cs</LastGenOutput> <LastGenOutput>MessageToken.cs</LastGenOutput>
</Content> </Content>
<Resource Include="Resources\Img\LeftMainContent\SortAscending_grey_16x.png" />
<Resource Include="Resources\Img\LeftMainContent\LinearCarousel_16x.png" /> <Resource Include="Resources\Img\LeftMainContent\LinearCarousel_16x.png" />
<Resource Include="Resources\Img\Album\1.jpg" /> <Resource Include="Resources\Img\Album\1.jpg" />
<Resource Include="Resources\Img\Album\10.jpg" /> <Resource Include="Resources\Img\Album\10.jpg" />
+10 -1
View File
@@ -47,7 +47,7 @@ namespace HandyControlDemo.Properties.Langs {
} }
/// <summary> /// <summary>
/// 使用此强类型资源类,为所有资源查找 /// 重写当前线程的 CurrentUICulture 属性
/// 重写当前线程的 CurrentUICulture 属性。 /// 重写当前线程的 CurrentUICulture 属性。
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
@@ -717,6 +717,15 @@ namespace HandyControlDemo.Properties.Langs {
} }
} }
/// <summary>
/// 查找类似 请输入关键字 的本地化字符串。
/// </summary>
public static string PlsEnterKey {
get {
return ResourceManager.GetString("PlsEnterKey", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 上一步 的本地化字符串。 /// 查找类似 上一步 的本地化字符串。
/// </summary> /// </summary>
@@ -462,4 +462,7 @@
<data name="CoverFlow" xml:space="preserve"> <data name="CoverFlow" xml:space="preserve">
<value>CoverFlow</value> <value>CoverFlow</value>
</data> </data>
<data name="PlsEnterKey" xml:space="preserve">
<value>Please input a keyword</value>
</data>
</root> </root>
@@ -442,4 +442,7 @@
<data name="CoverFlow" xml:space="preserve"> <data name="CoverFlow" xml:space="preserve">
<value>封面流</value> <value>封面流</value>
</data> </data>
<data name="PlsEnterKey" xml:space="preserve">
<value>请输入关键字</value>
</data>
</root> </root>
Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

@@ -15,7 +15,25 @@
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
<TabItem Background="Transparent" Header="{x:Static langs:Lang.Styles}"> <TabItem Background="Transparent" Header="{x:Static langs:Lang.Styles}">
<ListBox Name="listStyle" BorderThickness="0" SelectionMode="Single" Style="{StaticResource ListBoxTransparent}"> <Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<controls:SearchBar x:Name="SearchBarStyle" SearchStarted="SearchBarStyle_OnSearchStarted" Style="{StaticResource SearchBarPlus}" controls:InfoElement.Placeholder="{x:Static langs:Lang.PlsEnterKey}" Margin="4"/>
<ToggleButton Name="ButtonStyleAscending" Click="ButtonStyleAscending_OnClick" Grid.Row="0" Grid.Column="1" Margin="0,0,4,0" Style="{StaticResource ToggleButtonCustom}">
<Border CornerRadius="4" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" Height="30" Width="30" >
<Image Stretch="None" Source="/HandyControlDemo;component/Resources/Img/LeftMainContent/SortAscending_grey_16x.png"/>
</Border>
<controls:StatusSwitchElement.CheckedElement>
<Border CornerRadius="4" Height="30" Width="30" BorderThickness="1" BorderBrush="{DynamicResource PrimaryBrush}"/>
</controls:StatusSwitchElement.CheckedElement>
</ToggleButton>
<ListBox Name="listStyle" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" BorderThickness="0" SelectionMode="Single" Style="{StaticResource ListBoxTransparent}">
<ListBoxItem Tag="{x:Static data:MessageToken.BrushDemoCtl}" Content="{x:Static langs:Lang.Brush}"> <ListBoxItem Tag="{x:Static data:MessageToken.BrushDemoCtl}" Content="{x:Static langs:Lang.Brush}">
<controls:EdgeElement.LeftContent> <controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/Brush_16x.png"/> <Image Source="../../Resources/Img/LeftMainContent/Brush_16x.png"/>
@@ -142,9 +160,28 @@
</controls:EdgeElement.LeftContent> </controls:EdgeElement.LeftContent>
</ListBoxItem> </ListBoxItem>
</ListBox> </ListBox>
</Grid>
</TabItem> </TabItem>
<TabItem Background="Transparent" Header="{x:Static langs:Lang.Controls}"> <TabItem Background="Transparent" Header="{x:Static langs:Lang.Controls}">
<ListBox Name="listControl" BorderThickness="0" SelectionMode="Single" Style="{StaticResource ListBoxTransparent}"> <Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<controls:SearchBar SearchStarted="SearchBarControl_OnSearchStarted" Style="{StaticResource SearchBarPlus}" controls:InfoElement.Placeholder="{x:Static langs:Lang.PlsEnterKey}" Margin="4"/>
<ToggleButton Name="ButtonControlAscending" Click="ButtonControlAscending_OnClick" Grid.Row="0" Grid.Column="1" Margin="0,0,4,0" Style="{StaticResource ToggleButtonCustom}">
<Border CornerRadius="4" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" Height="30" Width="30" >
<Image Stretch="None" Source="/HandyControlDemo;component/Resources/Img/LeftMainContent/SortAscending_grey_16x.png"/>
</Border>
<controls:StatusSwitchElement.CheckedElement>
<Border CornerRadius="4" Height="30" Width="30" BorderThickness="1" BorderBrush="{DynamicResource PrimaryBrush}"/>
</controls:StatusSwitchElement.CheckedElement>
</ToggleButton>
<ListBox Name="listControl" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" BorderThickness="0" SelectionMode="Single" Style="{StaticResource ListBoxTransparent}">
<ListBoxItem Tag="{x:Static data:MessageToken.NumericUpDownDemoCtl}" Content="{x:Static langs:Lang.NumericUpDown}"> <ListBoxItem Tag="{x:Static data:MessageToken.NumericUpDownDemoCtl}" Content="{x:Static langs:Lang.NumericUpDown}">
<controls:EdgeElement.LeftContent> <controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/NumericListBox_16x.png"/> <Image Source="../../Resources/Img/LeftMainContent/NumericListBox_16x.png"/>
@@ -321,6 +358,7 @@
</controls:EdgeElement.LeftContent> </controls:EdgeElement.LeftContent>
</ListBoxItem> </ListBoxItem>
</ListBox> </ListBox>
</Grid>
</TabItem> </TabItem>
</TabControl> </TabControl>
</Border> </Border>
@@ -1,5 +1,9 @@
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using HandyControl.Data;
using HandyControl.Tools.Extension;
// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl namespace HandyControlDemo.UserControl
@@ -12,8 +16,6 @@ namespace HandyControlDemo.UserControl
public LeftMainContent() public LeftMainContent()
{ {
InitializeComponent(); InitializeComponent();
listStyle.Items.SortDescriptions.Add(new SortDescription("Content", ListSortDirection.Ascending));
listControl.Items.SortDescriptions.Add(new SortDescription("Content", ListSortDirection.Ascending));
} }
private void TabControl_OnSelectionChanged(object sender, SelectionChangedEventArgs e) private void TabControl_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -29,5 +31,49 @@ namespace HandyControlDemo.UserControl
} }
} }
} }
private void ButtonStyleAscending_OnClick(object sender, RoutedEventArgs e)
{
if (ButtonStyleAscending.IsChecked == true)
{
listStyle.Items.SortDescriptions.Add(new SortDescription("Content", ListSortDirection.Ascending));
}
else
{
listStyle.Items.SortDescriptions.Clear();
}
}
private void ButtonControlAscending_OnClick(object sender, RoutedEventArgs e)
{
if (ButtonControlAscending.IsChecked == true)
{
listControl.Items.SortDescriptions.Add(new SortDescription("Content", ListSortDirection.Ascending));
}
else
{
listControl.Items.SortDescriptions.Clear();
}
}
private void SearchBarStyle_OnSearchStarted(object sender, FunctionEventArgs<string> e)
{
if (e.Info == null) return;
foreach (var listBoxItem in listStyle.Items.OfType<ListBoxItem>())
{
listBoxItem.Show(listBoxItem.Content.ToString().Contains(e.Info));
}
}
private void SearchBarControl_OnSearchStarted(object sender, FunctionEventArgs<string> e)
{
if (e.Info == null) return;
foreach (var listBoxItem in listControl.Items.OfType<ListBoxItem>())
{
listBoxItem.Show(listBoxItem.Content.ToString().Contains(e.Info));
}
}
} }
} }