init
This commit is contained in:
@@ -0,0 +1,267 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
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 GridViewColumnHeaderSearchable.xaml
|
||||
/// </summary>
|
||||
public partial class GridViewColumnHeaderSearchable : 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 GridViewColumnHeaderSearchable()
|
||||
{
|
||||
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)
|
||||
{
|
||||
HeaderSearchTerm = string.Empty;
|
||||
}
|
||||
}
|
||||
public string ListviewId
|
||||
{
|
||||
get => (string) GetValue(ListviewIdProperty);
|
||||
set => SetValue(ListviewIdProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ListviewIdProperty =
|
||||
DependencyProperty.Register(
|
||||
"ListviewId",
|
||||
typeof(string),
|
||||
typeof(GridViewColumnHeaderSearchable), 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(GridViewColumnHeaderSearchable), // 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 GridViewColumnHeaderSearchable 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 static readonly DependencyProperty HeaderIsCheckedProperty =
|
||||
DependencyProperty.Register(
|
||||
"ToggleButtonIsChecked",
|
||||
typeof(bool),
|
||||
typeof(GridViewColumnHeaderSearchable),
|
||||
new PropertyMetadata(
|
||||
false,
|
||||
OnHeaderIsOpenChanged
|
||||
)
|
||||
);
|
||||
|
||||
private static void OnHeaderIsOpenChanged(
|
||||
DependencyObject d,
|
||||
DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (!(d is GridViewColumnHeaderSearchable 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(GridViewColumnHeaderSearchable));
|
||||
|
||||
// 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(GridViewColumnHeaderSearchable));
|
||||
|
||||
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)
|
||||
{
|
||||
if (LogicalTreeHelper.GetParent((DependencyObject) e.OriginalSource) is Popup popupParent)
|
||||
{
|
||||
//RaiseClickEvent(Tag);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void HeaderSearchTerm_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
|
||||
{
|
||||
RaiseSearchEvent(((TextBox) sender).Text);
|
||||
}
|
||||
|
||||
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(GridViewColumnHeaderSearchable), // 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 GridViewColumnHeaderSearchable 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(
|
||||
"Search", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(GridViewColumnHeaderSearchable));
|
||||
|
||||
// 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 class BoolToInvertedBoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value is bool boolValue)
|
||||
{
|
||||
return !boolValue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter,
|
||||
System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException("ConvertBack() of BoolToInvertedBoolConverter is not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user