Files
BeWoPlaner/BeWo/View/Search/TextModuleTreeSearchView.xaml.cs

116 lines
3.6 KiB
C#
Raw Normal View History

2018-03-02 17:24:44 +01:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using BeWo.Annotations;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
namespace BeWo.View.Search
{
public partial class TextModuleTreeSearchView : INotifyPropertyChanged
{
private BindingList<TextModuleDC> _List;
private readonly List<TextModuleDC> _AllTextModules = new List<TextModuleDC>();
public BindingList<TextModuleDC> List
{
get => _List ?? new BindingList<TextModuleDC>();
set
{
_List = value;
OnPropertyChanged(nameof(List));
}
}
public TextModuleTreeSearchView()
{
InitializeComponent();
DataContext = this;
}
public void InitSearchView(List<TextModuleDC> pAllTextModules)
{
_AllTextModules.Clear();
_AllTextModules.AddRange(pAllTextModules);
List = new BindingList<TextModuleDC>(_AllTextModules);
}
public long ServiceCategoryOid { get; set; }
public TextModuleDC SelectedItem { get; set; }
public event EventHandler<EventArgs<TextModuleDC>> ItemSelected;
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void TreeListControl_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var hitInfo = TreeListView.CalcHitInfo(e.OriginalSource as DependencyObject);
if(hitInfo.InRowCell)
{
SelectedItem = (TextModuleDC)TreeListControl.SelectedItem;
if(SelectedItem != null && !SelectedItem.IsParent)
{
ItemSelected?.Invoke(this, new EventArgs<TextModuleDC>(SelectedItem));
}
}
e.Handled = false;
}
public void UpdateFilteredList()
{
if(string.IsNullOrEmpty(TextBoxSearch.Text))
{
List = new BindingList<TextModuleDC>(_AllTextModules);
return;
}
var lFilter = TextBoxSearch.Text.ToLower().Split(" ");
2022-11-09 09:44:24 +01:00
var directHits = _AllTextModules.Where(w => w.Text != null && w.Name != null && (lFilter.Any(w.Text.ToLower().Contains) || lFilter.Any(w.Name.ToLower().Contains))).ToList();
2018-03-02 17:24:44 +01:00
directHits.AddRangeIfElementsNotIn(Utils.GetParentTextModules(directHits));
List = new BindingList<TextModuleDC>(directHits);
}
private void TextBoxSearch_OnTextChanged(object sender, TextChangedEventArgs e)
{
UpdateFilteredList();
}
}
public class TextModuleFontWeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var isParent = value != null && (bool) value;
return isParent ? FontWeights.Bold : FontWeights.Normal;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}