Skip to content

Commit

Permalink
add the list filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasZJ committed Apr 14, 2020
1 parent 9ac4204 commit 0b87ec1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Excel2Json/Excel2Json/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</ListBox.ItemTemplate>
</ListBox>
</materialDesign:PopupBox>
<TextBox Margin="0,0,10,0" MinWidth="200" DockPanel.Dock="Right" materialDesign:HintAssist.Hint="Filter in list" Style="{StaticResource MaterialDesignFloatingHintTextBox}" x:Name="FilterList_TextBox" TextChanged="TextBox_TextChanged"></TextBox>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Toolbox" Width="32" Height="32" >
<materialDesign:PackIcon.Background>
Expand Down Expand Up @@ -58,7 +59,6 @@
<Button x:Name="ExcelPathBtn" Content="..." Margin="0,5,10,0" VerticalAlignment="Top" Click="Button_Click" HorizontalAlignment="Right" Width="45" Style="{StaticResource MaterialDesignRaisedDarkButton}" materialDesign:ButtonAssist.CornerRadius="15" />
<Button x:Name="JsonPathBtn" Content="..." Margin="0,45,10,0" VerticalAlignment="Top" Click="Button_Click" HorizontalAlignment="Right" Width="45" Style="{StaticResource MaterialDesignRaisedDarkButton}" materialDesign:ButtonAssist.CornerRadius="15" />
<Button x:Name="DotTemplateFilePathBtn" Content="..." Margin="0,85,10,0" VerticalAlignment="Top" Click="Button_Click" HorizontalAlignment="Right" Width="45" Style="{StaticResource MaterialDesignRaisedDarkButton}" materialDesign:ButtonAssist.CornerRadius="15" />

</Grid>
<Grid Grid.Row="1" VerticalAlignment="Top" Margin="0,20,0,20">
<ListView x:Name="ExcelListView" Margin="10,0,10,0" Cursor="Hand" MouseLeftButtonUp="ListView_MouseClick" Style="{StaticResource MaterialDesignListView}">
Expand Down
21 changes: 20 additions & 1 deletion Excel2Json/Excel2Json/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Security.Cryptography;
using System.Windows.Documents;
using System.Collections.Generic;
using System.Windows.Data;

namespace Excel2
{
Expand Down Expand Up @@ -167,6 +168,8 @@ private void Grid_Loaded(object sender, RoutedEventArgs e)
mMainGrid = sender as Grid;

ExcelListView.ItemsSource = ListViweItemData;
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(ExcelListView.ItemsSource);
view.Filter = UserFilter;

ExcelPath_TextBox.DataContext = ExcelPath;
JsonPath_TextBox.DataContext = JsonPath;
Expand Down Expand Up @@ -359,9 +362,15 @@ private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs
private void TextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
TextBox tb = sender as TextBox;
UpdateText(tb, tb.Text);
if (tb.Name.Equals("FilterList_TextBox"))
{
CollectionViewSource.GetDefaultView(ExcelListView.ItemsSource).Refresh();
}
else
UpdateText(tb, tb.Text);
}


private void Textbox_DragEnter(object sender, DragEventArgs e)
{
//TextBox tb = sender as TextBox;
Expand Down Expand Up @@ -606,6 +615,7 @@ private void ShowFileList()

if (ProgressBar != null)
ProgressBar.Value = 0;

}

private void SetColor(string _colorName, string _theme)
Expand Down Expand Up @@ -667,5 +677,14 @@ private void UpdateText(TextBox _textBox, string _name)
break;
}
}

private bool UserFilter(object item)
{
if (String.IsNullOrEmpty(FilterList_TextBox.Text))
return true;
else
return ((item as ListViewItemData).FileName.IndexOf(FilterList_TextBox.Text, StringComparison.OrdinalIgnoreCase) >= 0);
}

}
}

0 comments on commit 0b87ec1

Please sign in to comment.