123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using InABox.Configuration;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace InABox.Wpf;
- public class FilterButton<T> : Button
- {
- public event DynamicGridFilterComponent<T>.FilterSelectedHandler? OnFiltersSelected
- {
- add { Component.OnFiltersSelected += value; }
- remove { Component.OnFiltersSelected -= value; }
- }
- public event DynamicGridFilterComponent<T>.FilterRefreshHandler? OnFilterRefresh
- {
- add { Component.OnFilterRefresh += value; }
- remove { Component.OnFilterRefresh -= value; }
- }
- private class ButtonComponent : DynamicGridFilterComponent<T>
- {
- private FilterButton<T> Button;
- public ButtonComponent(
- FilterButton<T> button,
- IConfiguration<CoreFilterDefinitions> globalConfiguration,
- IConfiguration<CoreFilterDefinitions> userConfiguration) : base(globalConfiguration, userConfiguration)
- {
- Button = button;
- }
- protected override void UpdateButtonText(System.Drawing.Bitmap image, string text)
- {
- Button.Update(image, text);
- }
- public void Click()
- {
- DoFilter();
- }
- }
- private ButtonComponent Component;
- public FilterButton(
- IConfiguration<CoreFilterDefinitions> globalConfiguration,
- IConfiguration<CoreFilterDefinitions> userConfiguration)
- {
- Component = new(this, globalConfiguration, userConfiguration);
- SetValue(BorderBrushProperty, new SolidColorBrush(Colors.Gray));
- SetValue(BorderThicknessProperty, new Thickness(0.75));
- Height = 30;
- Update(Wpf.Resources.filter, "");
- }
- public void SetSettings(DynamicGridSelectedFilterSettings settings, bool refresh)
- {
- Component.SetSettings(settings, refresh);
- }
- private void Update(System.Drawing.Bitmap image, string text)
- {
- var stackPnl = new StackPanel();
- stackPnl.Orientation = Orientation.Horizontal;
- //stackPnl.Margin = new Thickness(2);
- if (image != null)
- {
- var img = new Image
- {
- Source = image.AsBitmapImage(),
- Margin = new Thickness(2)
- };
- stackPnl.Children.Add(img);
- }
- if (!string.IsNullOrEmpty(text))
- {
- stackPnl.MaxWidth = double.MaxValue;
- var lbl = new Label();
- lbl.Content = text;
- lbl.VerticalAlignment = VerticalAlignment.Stretch;
- lbl.VerticalContentAlignment = VerticalAlignment.Center;
- lbl.Margin = new Thickness(2, 0, 5, 0);
- lbl.ToolTip = ToolTip;
- stackPnl.Children.Add(lbl);
- }
- else
- {
- stackPnl.MaxWidth = 30;
- }
- Content = stackPnl;
- }
- protected override void OnClick()
- {
- base.OnClick();
- Component.Click();
- }
- public Filter<T>? GetFilter()
- {
- return Component.GetFilter();
- }
- }
|