Skip to content

Commit

Permalink
Added filter textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Timthreetwelve committed Jun 23, 2021
1 parent 9735e46 commit fe28b40
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 2 deletions.
91 changes: 91 additions & 0 deletions HWiNFOVSBViewer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,73 @@
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Margin" Value="5,0,10,0" />
</Style>
<Style x:Key="MyWaterMarkStyle" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<Border
Background="White"
BorderBrush="LightGray"
BorderThickness="1" />
<ScrollViewer
x:Name="PART_ContentHost"
Margin="5,0,0,0"
VerticalAlignment="Center" />
<Label
x:Name="WaterMarkLabel"
Margin="5,-3,0,0"
VerticalAlignment="Center"
Content="{TemplateBinding Tag}"
FontSize="14"
Foreground="LightGray"
Visibility="Collapsed" />
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Text" Value="" />
</MultiTrigger.Conditions>
<Setter TargetName="WaterMarkLabel" Property="Visibility" Value="Visible" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="DimGray" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="myButton" TargetType="{x:Type Button}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Padding" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="grid">
<Border
x:Name="border"
Background="White"
BorderBrush="White"
BorderThickness="1">

<ContentPresenter
HorizontalAlignment="Center"
VerticalAlignment="Center"
TextElement.FontWeight="Normal" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Background" Value="Red" />
<Setter TargetName="border" Property="TextElement.Foreground" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<!--#endregion-->

Expand Down Expand Up @@ -116,6 +183,30 @@
InputGestureText="F1" />
</MenuItem>
</Menu>
<!--#region Search box-->
<StackPanel Margin="150,-24,0,0" Orientation="Horizontal">
<TextBox
x:Name="tbxSearch"
Width="200"
Height="24"
FontSize="15"
Style="{StaticResource MyWaterMarkStyle}"
Tag="Filter Text"
TextChanged="TbxSearch_TextChanged" />
<Button
x:Name="btnSearch"
Width="12"
Height="15"
Margin="-20,0,0,0"
Background="White"
BorderThickness="0"
Click="BtnSearch_Click"
Content="X"
FontSize="10"
Foreground="Red"
Style="{DynamicResource myButton}" />
</StackPanel>
<!--#endregion-->
</DockPanel>
<!--#endregion-->

Expand Down
25 changes: 25 additions & 0 deletions HWiNFOVSBViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.Win32;
Expand Down Expand Up @@ -266,6 +267,30 @@ private void MnuAbout_Click(object sender, RoutedEventArgs e)
{
ShowAbout();
}

private void TbxSearch_TextChanged(object sender, TextChangedEventArgs e)
{
string filter = tbxSearch.Text;

// I really don't understand how this works
ICollectionView cv = CollectionViewSource.GetDefaultView(HWGrid.ItemsSource);
cv.Filter = filter?.Length == 0
? (Predicate<object>)null
: (o =>
{
HWiNFO hw = o as HWiNFO;
return hw.Label.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0 ||
hw.Sensor.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0 ||
hw.Value.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0 ||
hw.Index.ToString().IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0;
});
btnSearch.IsEnabled = !string.IsNullOrEmpty(tbxSearch.Text);
}

private void BtnSearch_Click(object sender, RoutedEventArgs e)
{
tbxSearch.Clear();
}
#endregion Menu events

#region Window events
Expand Down
4 changes: 2 additions & 2 deletions HWiNFOVSBViewer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.2.173")]
[assembly: AssemblyFileVersion("0.1.2.173")]
[assembly: AssemblyVersion("0.1.3.174")]
[assembly: AssemblyFileVersion("0.1.3.174")]

0 comments on commit fe28b40

Please sign in to comment.