1.RecipeEditorView和RecipeSelectView优化过滤功能

This commit is contained in:
HCL 2024-05-24 11:27:33 +08:00
parent 1b465ec3f6
commit b7a1a2a195
5 changed files with 122 additions and 4 deletions

View File

@ -296,6 +296,7 @@
<Style BasedOn="{StaticResource TreeViewItemExtend}" TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="Visibility" Value="{Binding IsMatch, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
<i:Interaction.Triggers>

View File

@ -1893,9 +1893,8 @@ namespace MECF.Framework.UI.Client.CenterViews.Editors.Recipe
private void ApplyFilter()
{
ProcessTypeFileList[ProcessTypeIndexSelection].FilterFileListByProcessType =
new ObservableCollection<FileNode>(ProcessTypeFileList[ProcessTypeIndexSelection].FileListByProcessType
.Where(d => d.Name.IndexOf(CurrentCriteria, StringComparison.OrdinalIgnoreCase) >= 0));
foreach (var node in ProcessTypeFileList[ProcessTypeIndexSelection].FileListByProcessType)
node.ApplyCriteria(CurrentCriteria, new Stack<FileNode>());
}
public void ClearFilter()

View File

@ -62,10 +62,61 @@
BorderThickness="0,1,0,0">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0 0 0 3">
<Label
Margin="5,0,0,0"
VerticalAlignment="Center"
Content="Filter"
FontSize="16" />
<TextBox
Width="226"
Height="26"
Margin="0,0,5,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Text="{Binding CurrentCriteria, UpdateSourceTrigger=PropertyChanged}" />
<Button
Width="30"
Height="30"
Margin="0,0,5,0"
Padding="0"
HorizontalAlignment="Right"
VerticalAlignment="Center">
<Button.Content>
<Path
Width="15"
Height="15"
Margin="0,3"
Data="M5.5,0 L8.5,0 8.5,5.5 14,5.5 14,8.5 8.5,8.5 8.5,14 5.5,14 5.5,8.5 0,8.5 0,5.5 5.5,5.5 z"
Fill="Black"
RenderTransformOrigin="0.5,0.5"
Stretch="Fill"
StrokeThickness="3">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform />
<RotateTransform Angle="45" />
<TranslateTransform />
</TransformGroup>
</Path.RenderTransform>
</Path>
</Button.Content>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="ClearFilter" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
<Border
Grid.Row="1"
Background="Transparent"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0">
@ -98,6 +149,7 @@
<Style BasedOn="{StaticResource TreeViewItemExtend}" TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="Visibility" Value="{Binding IsMatch, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
<i:Interaction.Triggers>
@ -120,8 +172,9 @@
</TabControl>
</Border>
<StackPanel
Grid.Row="1"
Grid.Row="2"
Margin="0,10,0,0"
HorizontalAlignment="Center"
Orientation="Horizontal">

View File

@ -142,5 +142,29 @@ namespace MECF.Framework.UI.Client.CenterViews.Editors.Recipe
}
#endregion
private string _currentCriteria = string.Empty;
public string CurrentCriteria
{
get => _currentCriteria;
set
{
if (value == _currentCriteria)
return;
_currentCriteria = value;
NotifyOfPropertyChange(nameof(CurrentCriteria));
ApplyFilter();
}
}
private void ApplyFilter()
{
foreach (var node in ProcessTypeFileList[ProcessTypeIndexSelection].FileListByProcessType)
node.ApplyCriteria(CurrentCriteria, new Stack<FileNode>());
}
}
}

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Xml;
using Aitex.Core.UI.View.Common;
@ -46,6 +47,14 @@ namespace MECF.Framework.UI.Client.CenterViews.Editors.Sequence
public bool IsExpanded { get; set; }
private Visibility isMatch;
public Visibility IsMatch
{
get { return isMatch; }
set { isMatch = value; NotifyOfPropertyChange("IsMatch"); }
}
#endregion
#region Methods
@ -79,6 +88,38 @@ namespace MECF.Framework.UI.Client.CenterViews.Editors.Sequence
Refresh();
}
private bool IsCriteriaMatched(string criteria)
{
bool matched = string.IsNullOrEmpty(criteria) || _name.ToLower().Contains(criteria.ToLower());
if (matched)
return true;
return false;
}
public void ApplyCriteria(string criteria, Stack<FileNode> ancestors)
{
if (IsCriteriaMatched(criteria))
{
IsMatch = Visibility.Visible;
foreach (var ancestor in ancestors)
{
ancestor.IsMatch = Visibility.Visible;
ancestor.IsExpanded = !string.IsNullOrEmpty(criteria);
}
IsExpanded = true;
}
else
IsMatch = Visibility.Collapsed;
ancestors.Push(this);
foreach (var child in Files)
child.ApplyCriteria(criteria, ancestors);
ancestors.Pop();
}
#endregion
}