207 lines
7.5 KiB
C#
207 lines
7.5 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 Prism.Events;
|
|
using Prism.Ioc;
|
|
|
|
namespace DTS.Common.Controls
|
|
{
|
|
/// <inheritdoc cref="IBasePropertyChanged" />
|
|
/// <summary>
|
|
/// Interaction logic for GridViewColumnHeaderSelectable.xaml
|
|
/// </summary>
|
|
public partial class GridViewColumnHeaderSelectable : 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 GridViewColumnHeaderSelectable()
|
|
{
|
|
InitializeComponent();
|
|
var eventAggregator = ContainerLocator.Container.Resolve<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(GridViewColumnHeaderSelectable), 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(GridViewColumnHeaderSelectable), // 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 GridViewColumnHeaderSelectable 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(GridViewColumnHeaderSelectable),
|
|
new PropertyMetadata(
|
|
false,
|
|
OnHeaderIsOpenChanged
|
|
)
|
|
);
|
|
|
|
private static void OnHeaderIsOpenChanged(
|
|
DependencyObject d,
|
|
DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (!(d is GridViewColumnHeaderSelectable 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(GridViewColumnHeaderSelectable));
|
|
|
|
// 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(GridViewColumnHeaderSelectable));
|
|
|
|
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)
|
|
{
|
|
RaiseSelectAllEvent(true);
|
|
}
|
|
private void ClearAllButton_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseSelectAllEvent(false);
|
|
}
|
|
|
|
// Create a custom routed event by first registering a RoutedEventID
|
|
// This event uses the bubbling routing strategy
|
|
public static readonly RoutedEvent SelectAllEvent = EventManager.RegisterRoutedEvent(
|
|
"SelectAll", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(GridViewColumnHeaderSelectable));
|
|
|
|
// Provide CLR accessors for the event
|
|
public event RoutedEventHandler SelectAll
|
|
{
|
|
add => AddHandler(SelectAllEvent, value);
|
|
remove => RemoveHandler(SelectAllEvent, value);
|
|
}
|
|
|
|
// This method raises the Tap event
|
|
private void RaiseSelectAllEvent(bool selectAll)
|
|
{
|
|
var newEventArgs = new RoutedEventArgs(SelectAllEvent, selectAll);
|
|
RaiseEvent(newEventArgs);
|
|
OnPropertyChanged("ToggleIconGeometry");
|
|
}
|
|
}
|
|
} |