269 lines
10 KiB
C#
269 lines
10 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Windows;
|
|||
|
|
using System.Windows.Controls;
|
|||
|
|
using System.Windows.Data;
|
|||
|
|
using System.Windows.Media;
|
|||
|
|
using DTS.Common.Base;
|
|||
|
|
using DTS.Common.Events;
|
|||
|
|
using DTS.Common.Utilities.Logging;
|
|||
|
|
using Microsoft.Practices.Prism.Events;
|
|||
|
|
using Microsoft.Practices.ServiceLocation;
|
|||
|
|
|
|||
|
|
namespace DTS.Common.Controls
|
|||
|
|
{
|
|||
|
|
/// <inheritdoc cref="IBasePropertyChanged" />
|
|||
|
|
/// <summary>
|
|||
|
|
/// Interaction logic for GridViewColumnHeaderSelectable.xaml
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class GridViewColumnHeaderSearchableCheckBox : UserControl, IBasePropertyChanged
|
|||
|
|
{
|
|||
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|||
|
|
|
|||
|
|
public bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
|||
|
|
{
|
|||
|
|
if (Equals(storage, value)) return false;
|
|||
|
|
|
|||
|
|
storage = value;
|
|||
|
|
OnPropertyChanged(propertyName);
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnPropertyChanged(string propertyName = null)
|
|||
|
|
{
|
|||
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|||
|
|
}
|
|||
|
|
public GridViewColumnHeaderSearchableCheckBox()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
|
|||
|
|
eventAggregator.GetEvent<ListViewStatusEvent>().Subscribe(OnListviewStatusEvent, ThreadOption.UIThread);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override string ToString()
|
|||
|
|
{
|
|||
|
|
return HeaderTitle;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnListviewStatusEvent(ListViewStatusArg arg)
|
|||
|
|
{
|
|||
|
|
if (arg.Status != ListViewStatusArg.ListViewStatus.Unloaded)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (arg.Id == ListviewId)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public string ListviewId
|
|||
|
|
{
|
|||
|
|
get => (string) GetValue(ListviewIdProperty);
|
|||
|
|
set => SetValue(ListviewIdProperty, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static readonly DependencyProperty ListviewIdProperty =
|
|||
|
|
DependencyProperty.Register(
|
|||
|
|
"ListviewId",
|
|||
|
|
typeof(string),
|
|||
|
|
typeof(GridViewColumnHeaderSearchableCheckBox), new PropertyMetadata(""));
|
|||
|
|
|
|||
|
|
public string HeaderTitle
|
|||
|
|
{
|
|||
|
|
get => (string) GetValue(HeaderTitleProperty);
|
|||
|
|
set => SetValue(HeaderTitleProperty, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Using a DependencyProperty enables animation, styling, binding, etc.
|
|||
|
|
public static readonly DependencyProperty HeaderTitleProperty =
|
|||
|
|
DependencyProperty.Register(
|
|||
|
|
"HeaderTitle", // The name of the DependencyProperty
|
|||
|
|
typeof(string), // The type of the DependencyProperty
|
|||
|
|
typeof(GridViewColumnHeaderSearchableCheckBox), // The type of the owner of the DependencyProperty
|
|||
|
|
new PropertyMetadata( // OnHeaderTitleChanged will be called when HeaderTitle changes
|
|||
|
|
"Awesome", // The default value of the DependencyProperty
|
|||
|
|
OnHeaderTitleChanged
|
|||
|
|
)
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
private static void OnHeaderTitleChanged(
|
|||
|
|
DependencyObject d,
|
|||
|
|
DependencyPropertyChangedEventArgs e
|
|||
|
|
)
|
|||
|
|
{
|
|||
|
|
if (d is GridViewColumnHeaderSearchableCheckBox instance)
|
|||
|
|
{
|
|||
|
|
instance.HeaderTitle = (string) e.NewValue;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private bool _toggleButtonIsChecked = false;
|
|||
|
|
/// <summary>
|
|||
|
|
/// holds whether the toggle button is checked or not and controls whether the popup is open or not
|
|||
|
|
/// </summary>
|
|||
|
|
public bool ToggleButtonIsChecked
|
|||
|
|
{
|
|||
|
|
get => _toggleButtonIsChecked;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
if (value == _toggleButtonIsChecked) return;
|
|||
|
|
_toggleButtonIsChecked = value;
|
|||
|
|
OnPropertyChanged("ToggleButtonIsChecked");
|
|||
|
|
OnPropertyChanged("ToggleIconGeometry");
|
|||
|
|
RaiseOpenChangedEvent(value);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public Geometry ToggleIconGeometry
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if(string.IsNullOrEmpty(HeaderSearchTerm))
|
|||
|
|
{
|
|||
|
|
return (Geometry)dtsGridViewColumnHeader.FindResource("DownArrowIconGeometry");
|
|||
|
|
}
|
|||
|
|
return (Geometry)dtsGridViewColumnHeader.FindResource("FilterIconGeometry");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public string HeaderSearchTerm
|
|||
|
|
{
|
|||
|
|
get => (string)GetValue(HeaderSearchTermProperty);
|
|||
|
|
set => SetValue(HeaderSearchTermProperty, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Using a DependencyProperty enables animation, styling, binding, etc.
|
|||
|
|
public static readonly DependencyProperty HeaderSearchTermProperty =
|
|||
|
|
DependencyProperty.Register(
|
|||
|
|
"HeaderSearchTerm", // The name of the DependencyProperty
|
|||
|
|
typeof(string), // The type of the DependencyProperty
|
|||
|
|
typeof(GridViewColumnHeaderSearchableCheckBox), // The type of the owner of the DependencyProperty
|
|||
|
|
new PropertyMetadata( // OnHeaderTitleChanged will be called when HeaderTitle changes
|
|||
|
|
"", // The default value of the DependencyProperty
|
|||
|
|
OnHeaderSearchTermChanged
|
|||
|
|
)
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
private static void OnHeaderSearchTermChanged(
|
|||
|
|
DependencyObject d,
|
|||
|
|
DependencyPropertyChangedEventArgs e
|
|||
|
|
)
|
|||
|
|
{
|
|||
|
|
if (!(d is GridViewColumnHeaderSearchableCheckBox instance)) return;
|
|||
|
|
instance.HeaderSearchTerm = (string)e.NewValue;
|
|||
|
|
instance.RaiseSearchEvent((string)e.NewValue);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Create a custom routed event by first registering a RoutedEventID
|
|||
|
|
// This event uses the bubbling routing strategy
|
|||
|
|
public static readonly RoutedEvent SearchEvent = EventManager.RegisterRoutedEvent(
|
|||
|
|
"SearchCheckBox", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(GridViewColumnHeaderSearchableCheckBox));
|
|||
|
|
|
|||
|
|
// Provide CLR accessors for the event
|
|||
|
|
public event RoutedEventHandler Search
|
|||
|
|
{
|
|||
|
|
add => AddHandler(SearchEvent, value);
|
|||
|
|
remove => RemoveHandler(SearchEvent, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// This method raises the Tap event
|
|||
|
|
private void RaiseSearchEvent(string searchTerm)
|
|||
|
|
{
|
|||
|
|
var newEventArgs = new RoutedEventArgs(SearchEvent, searchTerm);
|
|||
|
|
RaiseEvent(newEventArgs);
|
|||
|
|
OnPropertyChanged("ToggleIconGeometry");
|
|||
|
|
}
|
|||
|
|
public static readonly DependencyProperty HeaderIsCheckedProperty =
|
|||
|
|
DependencyProperty.Register(
|
|||
|
|
"ToggleButtonIsChecked",
|
|||
|
|
typeof(bool),
|
|||
|
|
typeof(GridViewColumnHeaderSearchableCheckBox),
|
|||
|
|
new PropertyMetadata(
|
|||
|
|
false,
|
|||
|
|
OnHeaderIsOpenChanged
|
|||
|
|
)
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
private static void OnHeaderIsOpenChanged(
|
|||
|
|
DependencyObject d,
|
|||
|
|
DependencyPropertyChangedEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (!(d is GridViewColumnHeaderSearchableCheckBox instance)) return;
|
|||
|
|
instance.ToggleButtonIsChecked = (bool)e.NewValue;
|
|||
|
|
var isOpen = instance.ToggleButtonIsChecked;
|
|||
|
|
instance.RaiseOpenChangedEvent(isOpen);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Create a custom routed event by first registering a RoutedEventID
|
|||
|
|
// This event uses the bubbling routing strategy
|
|||
|
|
public static readonly RoutedEvent OpenChangedEvent = EventManager.RegisterRoutedEvent(
|
|||
|
|
"OpenChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(GridViewColumnHeaderSearchableCheckBox));
|
|||
|
|
|
|||
|
|
// Provide CLR accessors for the event
|
|||
|
|
public event RoutedEventHandler OpenChanged
|
|||
|
|
{
|
|||
|
|
add => AddHandler(OpenChangedEvent, value);
|
|||
|
|
remove => RemoveHandler(OpenChangedEvent, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// This method raises the Tap event
|
|||
|
|
private void RaiseOpenChangedEvent(bool isOpen)
|
|||
|
|
{
|
|||
|
|
var newEventArgs = new RoutedEventArgs(OpenChangedEvent, isOpen);
|
|||
|
|
RaiseEvent(newEventArgs);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static readonly RoutedEvent ClickEvent = EventManager.RegisterRoutedEvent(
|
|||
|
|
"ClickHandler", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(GridViewColumnHeaderSearchableCheckBox));
|
|||
|
|
|
|||
|
|
public event RoutedEventHandler ClickHandler
|
|||
|
|
{
|
|||
|
|
add => AddHandler(ClickEvent, value);
|
|||
|
|
remove => RemoveHandler(ClickEvent, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void RaiseClickEvent(object tag)
|
|||
|
|
{
|
|||
|
|
var newEventArgs = new RoutedEventArgs(ClickEvent, tag);
|
|||
|
|
RaiseEvent(newEventArgs);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void PreviewLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|||
|
|
{
|
|||
|
|
RaiseClickEvent(Tag);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SelectAllButton_OnClick(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
RaiseFilterEvent(@"All");
|
|||
|
|
}
|
|||
|
|
private void TrueButton_OnClick(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
RaiseFilterEvent("True");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void FalseButton_OnClick(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
RaiseFilterEvent("False");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Create a custom routed event by first registering a RoutedEventID
|
|||
|
|
// This event uses the bubbling routing strategy
|
|||
|
|
public static readonly RoutedEvent FilterEvent = EventManager.RegisterRoutedEvent(
|
|||
|
|
"Filter", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(GridViewColumnHeaderSearchableCheckBox));
|
|||
|
|
|
|||
|
|
// Provide CLR accessors for the event
|
|||
|
|
public event RoutedEventHandler Filter
|
|||
|
|
{
|
|||
|
|
add => AddHandler(FilterEvent, value);
|
|||
|
|
remove => RemoveHandler(FilterEvent, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// This method raises the Tap event
|
|||
|
|
private void RaiseFilterEvent(string filter)
|
|||
|
|
{
|
|||
|
|
var newEventArgs = new RoutedEventArgs(FilterEvent, filter);
|
|||
|
|
RaiseEvent(newEventArgs);
|
|||
|
|
OnPropertyChanged("ToggleIconGeometry");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|