Kategorie

This commit is contained in:
Meik
2025-11-11 23:22:31 +01:00
parent 8cf1c84328
commit 5292a2cb0c
4 changed files with 175 additions and 159 deletions

View File

@@ -1,6 +1,7 @@
<UserControl x:Class="FasdDesktopUi.Basics.UserControls.HierarchicalSelectionControl" <UserControl x:Class="FasdDesktopUi.Basics.UserControls.HierarchicalSelectionControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:FasdDesktopUi.Basics.UserControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ico="clr-namespace:FasdDesktopUi.Basics.UserControls.AdaptableIcon;assembly=F4SD-AdaptableIcon" xmlns:ico="clr-namespace:FasdDesktopUi.Basics.UserControls.AdaptableIcon;assembly=F4SD-AdaptableIcon"
@@ -15,75 +16,38 @@
<UserControl.Resources> <UserControl.Resources>
<vc:LanguageDefinitionsConverter x:Key="LanguageConverter" /> <vc:LanguageDefinitionsConverter x:Key="LanguageConverter" />
<vc:NullValueToVisibilityConverter x:Key="NullToVisibility" /> <vc:NullValueToVisibilityConverter x:Key="NullToVisibility" />
</UserControl.Resources>
<ControlTemplate x:Key="HierarchicalComboBoxTemplate"
TargetType="{x:Type ComboBox}">
<Grid> <Grid>
<Border x:Name="DisplayBorder" <ToggleButton x:Name="toggleButton"
Height="28" Grid.ColumnSpan="2"
Background="{Binding ElementName=HierarchySelector, Path=ComboBoxBackground}" Focusable="False"
BorderBrush="{Binding ElementName=HierarchySelector, Path=BorderBrush}" ClickMode="Press"
BorderThickness="1" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
CornerRadius="7.5" Background="{TemplateBinding Background}"
Padding="6 0" BorderBrush="{TemplateBinding BorderBrush}"
MouseLeftButtonUp="DisplayBorder_MouseLeftButtonUp"> BorderThickness="{TemplateBinding BorderThickness}"
<Border.Style> Style="{StaticResource ComboBoxToggleButton}" />
<Style TargetType="Border">
<Setter Property="Opacity" Value="1" />
<Setter Property="Cursor" Value="Hand" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsOpen, ElementName=DropDownPopup}"
Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource BackgroundColor.Menu.SubCategory.Hover}" />
<Setter Property="Background" Value="{DynamicResource BackgroundColor.DetailsPage.DataHistory.ValueColumn}" />
</DataTrigger>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource BackgroundColor.Menu.SubCategory.Hover}" />
</Trigger>
<DataTrigger Binding="{Binding ElementName=HierarchySelector, Path=IsEnabled}"
Value="False">
<Setter Property="Opacity" Value="0.5" />
<Setter Property="Cursor" Value="Arrow" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0"
Margin="0 0 10 0"
VerticalAlignment="Center">
<TextBlock Text="{Binding ElementName=HierarchySelector, Path=SelectedItem.FullPath}"
Foreground="{DynamicResource FontColor.Menu.Categories}"
VerticalAlignment="Center"
TextTrimming="CharacterEllipsis"
ToolTip="{Binding ElementName=HierarchySelector, Path=SelectedItem.FullPath}" />
</Grid>
<Path Grid.Column="1"
Margin="0 0 6 0"
Data="F1 M 2.89067,4.99467C 2.89067,4.22933 3.724,3.74533 4.39067,4.13067L 10.8227,7.844L 17.26,4.13067C 18.412,3.48 19.4013,5.19333 18.26,5.86533L 11.3227,9.86533C 11.016,10.0413 10.636,10.0413 10.3227,9.86533L 3.39067,5.86533C 3.07867,5.688 2.89067,5.35467 2.89067,4.99467 Z"
Fill="{DynamicResource Color.Menu.Icon}"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Width="10"
Height="6"
Stretch="Uniform"
IsHitTestVisible="False" />
</Grid>
</Border>
<Popup x:Name="DropDownPopup" <ContentPresenter x:Name="contentPresenter"
PlacementTarget="{Binding ElementName=DisplayBorder}" IsHitTestVisible="False"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Margin="6 0"
VerticalAlignment="Center"
HorizontalAlignment="Stretch" />
<Popup x:Name="PART_Popup"
Placement="Bottom" Placement="Bottom"
StaysOpen="False" PlacementTarget="{Binding ElementName=toggleButton}"
AllowsTransparency="True" AllowsTransparency="True"
Width="{Binding ElementName=DisplayBorder, Path=ActualWidth}" Focusable="False"
Opened="DropDownPopup_Opened" IsOpen="{TemplateBinding IsDropDownOpen}"
Closed="DropDownPopup_Closed"> PopupAnimation="Fade">
<Border Background="{DynamicResource BackgroundColor.Menu.SubCategory}" <Border Width="{Binding ActualWidth, ElementName=HierarchySelector}"
Background="{DynamicResource BackgroundColor.Menu.SubCategory}"
CornerRadius="7.5" CornerRadius="7.5"
Padding="10"> Padding="10">
<Border.Effect> <Border.Effect>
@@ -95,12 +59,11 @@
</Border.Effect> </Border.Effect>
<StackPanel> <StackPanel>
<Grid Margin="0 0 10 0"> <Grid Margin="0 0 10 0">
<TextBox x:Name="SearchTextBox" <TextBox x:Name="PART_SearchTextBox"
Style="{DynamicResource Customizable.Editable.TextBox.EditOnly}" Style="{DynamicResource Customizable.Editable.TextBox.EditOnly}"
Background="{Binding ElementName=HierarchySelector, Path=ComboBoxBackground}" Background="{TemplateBinding Background}"
Padding="27 5 5 5" Padding="27 5 5 5"
VerticalContentAlignment="Center" VerticalContentAlignment="Center" />
TextChanged="SearchTextBox_TextChanged" />
<ico:AdaptableIcon SelectedInternIcon="menuBar_search" <ico:AdaptableIcon SelectedInternIcon="menuBar_search"
Style="{DynamicResource Menu.MenuBar.PinnedIcon.Base}" Style="{DynamicResource Menu.MenuBar.PinnedIcon.Base}"
BorderPadding="5 5 5 7" BorderPadding="5 5 5 7"
@@ -116,10 +79,10 @@
<Style TargetType="TextBlock"> <Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" /> <Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers> <Style.Triggers>
<DataTrigger Binding="{Binding Text, ElementName=SearchTextBox}" <DataTrigger Binding="{Binding Text, ElementName=PART_SearchTextBox}"
Value=""> Value="">
<Setter Property="Text" <Setter Property="Text"
Value="{Binding ElementName=HierarchySelector, Path=SearchPlaceholderText}" /> Value="{Binding Path=SearchPlaceholderText, RelativeSource={RelativeSource AncestorType={x:Type local:HierarchicalSelectionControl}}}" />
<Setter Property="Visibility" Value="Visible" /> <Setter Property="Visibility" Value="Visible" />
</DataTrigger> </DataTrigger>
</Style.Triggers> </Style.Triggers>
@@ -134,10 +97,9 @@
CornerRadius="5"> CornerRadius="5">
<ScrollViewer MaxHeight="300" <ScrollViewer MaxHeight="300"
VerticalScrollBarVisibility="Auto"> VerticalScrollBarVisibility="Auto">
<TreeView x:Name="TreeViewControl" <TreeView x:Name="PART_TreeView"
Background="{Binding ElementName=HierarchySelector, Path=ComboBoxBackground}" Background="{DynamicResource BackgroundColor.Menu.SubCategory}"
ItemsSource="{Binding VisibleItems, ElementName=HierarchySelector}" ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource TemplatedParent}}">
SelectedItemChanged="TreeViewControl_SelectedItemChanged">
<TreeView.Resources> <TreeView.Resources>
<Style TargetType="TreeViewItem"> <Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" <Setter Property="IsExpanded"
@@ -157,4 +119,21 @@
</Border> </Border>
</Popup> </Popup>
</Grid> </Grid>
</ControlTemplate>
</UserControl.Resources>
<Grid>
<ComboBox x:Name="ComboBoxControl"
Background="{Binding ElementName=HierarchySelector, Path=ComboBoxBackground}"
BorderBrush="{Binding ElementName=HierarchySelector, Path=BorderBrush}"
Foreground="{DynamicResource FontColor.Menu.Categories}"
ItemsSource="{Binding VisibleItems, ElementName=HierarchySelector}"
SelectedItem="{Binding SelectedItem, ElementName=HierarchySelector, Mode=TwoWay}"
DisplayMemberPath="FullPath"
Template="{StaticResource HierarchicalComboBoxTemplate}"
DropDownOpened="ComboBoxControl_DropDownOpened"
DropDownClosed="ComboBoxControl_DropDownClosed"
IsEditable="False"
Padding="0" />
</Grid>
</UserControl> </UserControl>

View File

@@ -8,6 +8,7 @@ using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Threading; using System.Windows.Threading;
using static C4IT.Logging.cLogManager;
namespace FasdDesktopUi.Basics.UserControls namespace FasdDesktopUi.Basics.UserControls
{ {
@@ -17,6 +18,10 @@ namespace FasdDesktopUi.Basics.UserControls
private readonly Dictionary<string, HierarchicalSelectionItem> itemLookup = new Dictionary<string, HierarchicalSelectionItem>(); private readonly Dictionary<string, HierarchicalSelectionItem> itemLookup = new Dictionary<string, HierarchicalSelectionItem>();
private readonly DispatcherTimer searchDelayTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(250) }; private readonly DispatcherTimer searchDelayTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(250) };
private string lastSearchText = string.Empty; private string lastSearchText = string.Empty;
private TextBox searchTextBox;
private TreeView treeViewControl;
public ObservableCollection<HierarchicalSelectionItem> VisibleItems => visibleItems; public ObservableCollection<HierarchicalSelectionItem> VisibleItems => visibleItems;
public event EventHandler DropDownOpened; public event EventHandler DropDownOpened;
@@ -25,10 +30,18 @@ namespace FasdDesktopUi.Basics.UserControls
public HierarchicalSelectionControl() public HierarchicalSelectionControl()
{ {
InitializeComponent(); InitializeComponent();
TreeViewControl.ItemsSource = visibleItems;
searchDelayTimer.Tick += SearchDelayTimer_Tick; searchDelayTimer.Tick += SearchDelayTimer_Tick;
} }
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
EnsureTemplateParts();
if (treeViewControl != null)
treeViewControl.ItemsSource = VisibleItems;
UpdateDisplaySelection();
}
#region DependencyProperties #region DependencyProperties
public ObservableCollection<HierarchicalSelectionItem> ItemsSource public ObservableCollection<HierarchicalSelectionItem> ItemsSource
@@ -93,16 +106,19 @@ namespace FasdDesktopUi.Basics.UserControls
#endregion #endregion
private void DropDownPopup_Opened(object sender, EventArgs e) private void ComboBoxControl_DropDownOpened(object sender, EventArgs e)
{ {
SearchTextBox.Focus(); EnsureTemplateParts();
SearchTextBox.SelectAll(); searchTextBox?.Focus();
searchTextBox?.SelectAll();
LogEntry($"[CategoryPicker] DropDownOpened. Selected={SelectedItem?.FullPath ?? "<null>"}");
DropDownOpened?.Invoke(this, e); DropDownOpened?.Invoke(this, e);
} }
private void DropDownPopup_Closed(object sender, EventArgs e) private void ComboBoxControl_DropDownClosed(object sender, EventArgs e)
{ {
searchDelayTimer.Stop(); searchDelayTimer.Stop();
LogEntry("[CategoryPicker] DropDownClosed");
DropDownClosed?.Invoke(this, e); DropDownClosed?.Invoke(this, e);
} }
@@ -115,7 +131,8 @@ namespace FasdDesktopUi.Basics.UserControls
private void SearchDelayTimer_Tick(object sender, EventArgs e) private void SearchDelayTimer_Tick(object sender, EventArgs e)
{ {
searchDelayTimer.Stop(); searchDelayTimer.Stop();
lastSearchText = SearchTextBox.Text ?? string.Empty; lastSearchText = searchTextBox?.Text ?? string.Empty;
LogEntry($"[CategoryPicker] Search text changed: '{lastSearchText}'");
ApplyFilter(lastSearchText); ApplyFilter(lastSearchText);
} }
@@ -124,10 +141,13 @@ namespace FasdDesktopUi.Basics.UserControls
if (e.NewValue is HierarchicalSelectionItem selected) if (e.NewValue is HierarchicalSelectionItem selected)
{ {
var original = ResolveOriginalItem(selected); var original = ResolveOriginalItem(selected);
if (original != null) if (original != null && !Equals(SelectedItem, original))
{
SelectedItem = original; SelectedItem = original;
LogEntry($"[CategoryPicker] Tree selection changed: {original.FullPath}");
}
DropDownPopup.IsOpen = false; ComboBoxControl.IsDropDownOpen = false;
} }
} }
@@ -139,7 +159,7 @@ namespace FasdDesktopUi.Basics.UserControls
if (!string.IsNullOrWhiteSpace(item.Id) && itemLookup.TryGetValue(item.Id, out var original)) if (!string.IsNullOrWhiteSpace(item.Id) && itemLookup.TryGetValue(item.Id, out var original))
return original; return original;
return item; return null;
} }
private void RebuildLookup() private void RebuildLookup()
@@ -209,13 +229,29 @@ namespace FasdDesktopUi.Basics.UserControls
} }
} }
private void DisplayBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) private void EnsureTemplateParts()
{ {
if (!IsEnabled) if (treeViewControl == null)
return; {
treeViewControl = ComboBoxControl.Template.FindName("PART_TreeView", ComboBoxControl) as TreeView;
if (treeViewControl != null)
{
treeViewControl.SelectedItemChanged += TreeViewControl_SelectedItemChanged;
treeViewControl.ItemsSource = VisibleItems;
}
}
e.Handled = true; if (searchTextBox == null)
DropDownPopup.IsOpen = !DropDownPopup.IsOpen; {
searchTextBox = ComboBoxControl.Template.FindName("PART_SearchTextBox", ComboBoxControl) as TextBox;
if (searchTextBox != null)
searchTextBox.TextChanged += SearchTextBox_TextChanged;
}
}
private void UpdateDisplaySelection()
{
// Display handled by ComboBox DisplayMemberPath (FullPath).
} }
protected override void OnPreviewKeyDown(KeyEventArgs e) protected override void OnPreviewKeyDown(KeyEventArgs e)
@@ -225,16 +261,16 @@ namespace FasdDesktopUi.Basics.UserControls
if (!IsEnabled) if (!IsEnabled)
return; return;
if (!DropDownPopup.IsOpen && (e.Key == Key.Enter || e.Key == Key.Down || e.Key == Key.Space)) if (!ComboBoxControl.IsDropDownOpen && (e.Key == Key.Enter || e.Key == Key.Down || e.Key == Key.Space))
{ {
DropDownPopup.IsOpen = true; ComboBoxControl.IsDropDownOpen = true;
e.Handled = true; e.Handled = true;
return; return;
} }
if (DropDownPopup.IsOpen && e.Key == Key.Escape) if (ComboBoxControl.IsDropDownOpen && e.Key == Key.Escape)
{ {
DropDownPopup.IsOpen = false; ComboBoxControl.IsDropDownOpen = false;
e.Handled = true; e.Handled = true;
} }
} }

View File

@@ -166,6 +166,8 @@
ComboBoxBackground="{DynamicResource BackgroundColor.DetailsPage.DataHistory.ValueColumn}" ComboBoxBackground="{DynamicResource BackgroundColor.DetailsPage.DataHistory.ValueColumn}"
BorderBrush="{DynamicResource BackgroundColor.Menu.SubCategory.Hover}" BorderBrush="{DynamicResource BackgroundColor.Menu.SubCategory.Hover}"
SearchPlaceholderText="{Binding Converter={StaticResource LanguageConverter}, ConverterParameter=Searchbar.Placeholder}" SearchPlaceholderText="{Binding Converter={StaticResource LanguageConverter}, ConverterParameter=Searchbar.Placeholder}"
DropDownOpened="DropDownOpened"
DropDownClosed="DropDownClosed"
PreviewKeyDown="Combobox_PreviewKeyDown" /> PreviewKeyDown="Combobox_PreviewKeyDown" />
<StackPanel> <StackPanel>
<TextBlock Text="{Binding Converter={StaticResource LanguageConverter}, ConverterParameter=Dialog.CloseCase.Template}" <TextBlock Text="{Binding Converter={StaticResource LanguageConverter}, ConverterParameter=Dialog.CloseCase.Template}"

View File

@@ -2393,12 +2393,11 @@ namespace FasdDesktopUi.Basics.UserControls
#region DropDown #region DropDown
private static bool IsInsidePageable(FrameworkElement fe) => cUiElementHelper.GetFirstParentOfType<ComboBoxPageable>(fe) != null; private static bool IsInsidePageable(FrameworkElement fe) => cUiElementHelper.GetFirstParentOfType<ComboBoxPageable>(fe) != null;
private static bool IsHierarchicalControl(FrameworkElement fe) => fe is HierarchicalSelectionControl;
private void DropDownOpened(object sender, EventArgs e) private void DropDownOpened(object sender, EventArgs e)
{ {
if (!(sender is FrameworkElement fe)) return; if (!(sender is FrameworkElement fe)) return;
if (IsInsidePageable(fe) || IsHierarchicalControl(fe)) return; // Spezialfälle handeln Fokus selbst if (IsInsidePageable(fe)) return; // ComboBoxPageable fired itself
var parentBorder = cUiElementHelper.GetFirstParentOfType<Border>(fe); var parentBorder = cUiElementHelper.GetFirstParentOfType<Border>(fe);
if (parentBorder != null) if (parentBorder != null)
@@ -2408,7 +2407,7 @@ namespace FasdDesktopUi.Basics.UserControls
private void DropDownClosed(object sender, EventArgs e) private void DropDownClosed(object sender, EventArgs e)
{ {
if (!(sender is FrameworkElement fe)) return; if (!(sender is FrameworkElement fe)) return;
if (IsInsidePageable(fe) || IsHierarchicalControl(fe)) return; if (IsInsidePageable(fe)) return;
var parentBorder = cUiElementHelper.GetFirstParentOfType<Border>(fe); var parentBorder = cUiElementHelper.GetFirstParentOfType<Border>(fe);
if (parentBorder != null) if (parentBorder != null)