JD2022-TU1/main/tools/framework/JD.WPF/Controls/ExpanderContainer.cs

181 lines
8.8 KiB
C#

using System.Windows;
using System.Windows.Controls;
namespace JD.WPF.Controls
{
/// <summary>
/// Represents a specific container with a main view and an discreet overlay allowing the docking
/// of up to 8 additional controls (one on each border, one on each corner).
/// The display of each additional control is controlled by a toggle button in the overlay.
/// </summary>
public class ExpanderContainer : ContentControl
{
public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(FrameworkElement), typeof(ExpanderContainer), new UIPropertyMetadata(null));
public static readonly DependencyProperty TopProperty = DependencyProperty.Register("Top", typeof(FrameworkElement), typeof(ExpanderContainer), new UIPropertyMetadata(null));
public static readonly DependencyProperty TopLeftProperty = DependencyProperty.Register("TopLeft", typeof(FrameworkElement), typeof(ExpanderContainer), new UIPropertyMetadata(null));
public static readonly DependencyProperty TopRightProperty = DependencyProperty.Register("TopRight", typeof(FrameworkElement), typeof(ExpanderContainer), new UIPropertyMetadata(null));
public static readonly DependencyProperty LeftProperty = DependencyProperty.Register("Left", typeof(FrameworkElement), typeof(ExpanderContainer), new UIPropertyMetadata(null));
public static readonly DependencyProperty RightProperty = DependencyProperty.Register("Right", typeof(FrameworkElement), typeof(ExpanderContainer), new UIPropertyMetadata(null));
public static readonly DependencyProperty BottomProperty = DependencyProperty.Register("Bottom", typeof(FrameworkElement), typeof(ExpanderContainer), new UIPropertyMetadata(null));
public static readonly DependencyProperty BottomLeftProperty = DependencyProperty.Register("BottomLeft", typeof(FrameworkElement), typeof(ExpanderContainer), new UIPropertyMetadata(null));
public static readonly DependencyProperty BottomRightProperty = DependencyProperty.Register("BottomRight", typeof(FrameworkElement), typeof(ExpanderContainer), new UIPropertyMetadata(null));
public static readonly DependencyProperty TopVisibleProperty = DependencyProperty.Register("TopVisible", typeof(bool), typeof(ExpanderContainer), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty TopLeftVisibleProperty = DependencyProperty.Register("TopLeftVisible", typeof(bool), typeof(ExpanderContainer), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty TopRightVisibleProperty = DependencyProperty.Register("TopRightVisible", typeof(bool), typeof(ExpanderContainer), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty LeftVisibleProperty = DependencyProperty.Register("LeftVisible", typeof(bool), typeof(ExpanderContainer), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty RightVisibleProperty = DependencyProperty.Register("RightVisible", typeof(bool), typeof(ExpanderContainer), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty BottomVisibleProperty = DependencyProperty.Register("BottomVisible", typeof(bool), typeof(ExpanderContainer), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty BottomLeftVisibleProperty = DependencyProperty.Register("BottomLeftVisible", typeof(bool), typeof(ExpanderContainer), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty BottomRightVisibleProperty = DependencyProperty.Register("BottomRightVisible", typeof(bool), typeof(ExpanderContainer), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (Style == null)
Style = FindResource("ExpanderContainerBaseStyle") as Style;
}
public FrameworkElement Center
{
get { return (FrameworkElement) GetValue(CenterProperty); }
set { SetValue(CenterProperty, value); }
}
public FrameworkElement Top
{
get { return (FrameworkElement) GetValue(TopProperty); }
set { SetValue(TopProperty, value); }
}
public FrameworkElement TopLeft
{
get { return (FrameworkElement) GetValue(TopLeftProperty); }
set { SetValue(TopLeftProperty, value); }
}
public FrameworkElement TopRight
{
get { return (FrameworkElement) GetValue(TopRightProperty); }
set { SetValue(TopRightProperty, value); }
}
public FrameworkElement Left
{
get { return (FrameworkElement) GetValue(LeftProperty); }
set { SetValue(LeftProperty, value); }
}
public FrameworkElement Right
{
get { return (FrameworkElement) GetValue(RightProperty); }
set { SetValue(RightProperty, value); }
}
public FrameworkElement Bottom
{
get { return (FrameworkElement) GetValue(BottomProperty); }
set { SetValue(BottomProperty, value); }
}
public FrameworkElement BottomLeft
{
get { return (FrameworkElement) GetValue(BottomLeftProperty); }
set { SetValue(BottomLeftProperty, value); }
}
public FrameworkElement BottomRight
{
get { return (FrameworkElement) GetValue(BottomRightProperty); }
set { SetValue(BottomRightProperty, value); }
}
public bool TopVisible
{
get { return (bool) GetValue(TopVisibleProperty); }
set { SetValue(TopVisibleProperty, value); }
}
public bool TopLeftVisible
{
get { return (bool) GetValue(TopLeftVisibleProperty); }
set { SetValue(TopLeftVisibleProperty, value); }
}
public bool TopRightVisible
{
get { return (bool) GetValue(TopRightVisibleProperty); }
set { SetValue(TopRightVisibleProperty, value); }
}
public bool LeftVisible
{
get { return (bool) GetValue(LeftVisibleProperty); }
set { SetValue(LeftVisibleProperty, value); }
}
public bool RightVisible
{
get { return (bool) GetValue(RightVisibleProperty); }
set { SetValue(RightVisibleProperty, value); }
}
public bool BottomVisible
{
get { return (bool) GetValue(BottomVisibleProperty); }
set { SetValue(BottomVisibleProperty, value); }
}
public bool BottomLeftVisible
{
get { return (bool) GetValue(BottomLeftVisibleProperty); }
set { SetValue(BottomLeftVisibleProperty, value); }
}
public bool BottomRightVisible
{
get { return (bool) GetValue(BottomRightVisibleProperty); }
set { SetValue(BottomRightVisibleProperty, value); }
}
}
public class ExpanderContainerControl : ContentControl
{
public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register("IsExpanded", typeof(bool), typeof(ExpanderContainerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register("Location", typeof(ExpanderContainerLocation), typeof(ExpanderContainerControl), new FrameworkPropertyMetadata(ExpanderContainerLocation.Center));
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (Style == null)
Style = FindResource("ExpanderContainerControlBaseStyle") as Style;
}
public bool IsExpanded
{
get { return (bool) GetValue(IsExpandedProperty); }
set { SetValue(IsExpandedProperty, value); }
}
public ExpanderContainerLocation Location
{
get { return (ExpanderContainerLocation) GetValue(LocationProperty); }
set { SetValue(LocationProperty, value); }
}
}
public enum ExpanderContainerLocation
{
Center,
Top,
Left,
Bottom,
Right,
TopLeft,
TopRight,
BottomLeft,
BottomRight,
}
}