|
@@ -1,4 +1,7 @@
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Configuration;
|
|
|
+using System.Linq;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Data;
|
|
@@ -8,41 +11,46 @@ using Syncfusion.Windows.Controls.Input;
|
|
|
|
|
|
namespace InABox.DynamicGrid
|
|
|
{
|
|
|
+ [Flags]
|
|
|
public enum DynamicSplitPanelView
|
|
|
+ {
|
|
|
+ Master = 1,
|
|
|
+ Detail = 2,
|
|
|
+ Combined = 4
|
|
|
+ }
|
|
|
+
|
|
|
+ public enum DynamicSplitPanelAnchor
|
|
|
{
|
|
|
Master,
|
|
|
- Detail,
|
|
|
- Combined
|
|
|
+ Detail
|
|
|
}
|
|
|
|
|
|
- public class DynamicSplitPanelChangedArgs : EventArgs
|
|
|
+ public class DynamicSplitPanelSettings : EventArgs
|
|
|
{
|
|
|
public DynamicSplitPanelView View { get; set; }
|
|
|
- public double MasterWidth { get; set; }
|
|
|
+ public double AnchorWidth { get; set; }
|
|
|
public double DetailHeight { get; set; }
|
|
|
}
|
|
|
|
|
|
- public delegate void DynamicSplitPanelChanged(object sender, DynamicSplitPanelChangedArgs e);
|
|
|
+ public delegate void DynamicSplitPanelChanged(object sender, DynamicSplitPanelSettings e);
|
|
|
|
|
|
public class DynamicSplitPanel : Control
|
|
|
{
|
|
|
+
|
|
|
+ public static readonly DependencyProperty AllowableViewsProperty = DependencyProperty.Register(
|
|
|
+ nameof(AllowableViews),
|
|
|
+ typeof(DynamicSplitPanelView),
|
|
|
+ typeof(DynamicSplitPanel),
|
|
|
+ new UIPropertyMetadata( DynamicSplitPanelView.Master | DynamicSplitPanelView.Combined | DynamicSplitPanelView.Detail ));
|
|
|
+
|
|
|
public static readonly DependencyProperty ViewProperty = DependencyProperty.Register("View", typeof(DynamicSplitPanelView),
|
|
|
typeof(DynamicSplitPanel), new UIPropertyMetadata(DynamicSplitPanelView.Detail));
|
|
|
|
|
|
- //public static readonly DependencyProperty HeaderVisibilityProperty = DependencyProperty.Register("HeaderVisibility", typeof(Visibility), typeof(DynamicSplitPanel), new UIPropertyMetadata(null));
|
|
|
-
|
|
|
- //public Visibility HeaderVisibility
|
|
|
- //{
|
|
|
- // get { return (Visibility)GetValue(HeaderVisibilityProperty); }
|
|
|
- // set
|
|
|
- // {
|
|
|
- // SetValue(HeaderVisibilityProperty, value);
|
|
|
- // ConfigureScreen();
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- public static readonly DependencyProperty MasterWidthProperty =
|
|
|
- DependencyProperty.Register("MasterWidth", typeof(double), typeof(DynamicSplitPanel), new UIPropertyMetadata((double)300F));
|
|
|
+ public static readonly DependencyProperty AnchorProperty = DependencyProperty.Register(nameof(Anchor), typeof(DynamicSplitPanelAnchor),
|
|
|
+ typeof(DynamicSplitPanel), new UIPropertyMetadata(DynamicSplitPanelAnchor.Master));
|
|
|
+
|
|
|
+ public static readonly DependencyProperty AnchorWidthProperty =
|
|
|
+ DependencyProperty.Register(nameof(AnchorWidth), typeof(double), typeof(DynamicSplitPanel), new UIPropertyMetadata((double)300F));
|
|
|
|
|
|
public static readonly DependencyProperty MasterCaptionProperty =
|
|
|
DependencyProperty.Register("MasterCaption", typeof(string), typeof(DynamicSplitPanel), new UIPropertyMetadata(null));
|
|
@@ -86,6 +94,27 @@ namespace InABox.DynamicGrid
|
|
|
{
|
|
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(DynamicSplitPanel), new FrameworkPropertyMetadata(typeof(DynamicSplitPanel)));
|
|
|
}
|
|
|
+
|
|
|
+ public DynamicSplitPanelView AllowableViews
|
|
|
+ {
|
|
|
+ get => (DynamicSplitPanelView)GetValue(AllowableViewsProperty);
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetValue(AllowableViewsProperty, value);
|
|
|
+ ConfigureScreen();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool IsViewAllowed(params DynamicSplitPanelView[] views)
|
|
|
+ {
|
|
|
+ foreach (var view in views)
|
|
|
+ {
|
|
|
+ if ((AllowableViews & view) == view)
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
public DynamicSplitPanelView View
|
|
|
{
|
|
@@ -97,12 +126,22 @@ namespace InABox.DynamicGrid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public double MasterWidth
|
|
|
+ public DynamicSplitPanelAnchor Anchor
|
|
|
+ {
|
|
|
+ get => (DynamicSplitPanelAnchor)GetValue(AnchorProperty);
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetValue(AnchorProperty, value);
|
|
|
+ ConfigureScreen();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public double AnchorWidth
|
|
|
{
|
|
|
- get => (double)GetValue(MasterWidthProperty);
|
|
|
+ get => (double)GetValue(AnchorWidthProperty);
|
|
|
set
|
|
|
{
|
|
|
- SetValue(MasterWidthProperty, value);
|
|
|
+ SetValue(AnchorWidthProperty, value);
|
|
|
ConfigureScreen();
|
|
|
}
|
|
|
}
|
|
@@ -181,6 +220,8 @@ namespace InABox.DynamicGrid
|
|
|
Changed();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void ConfigureScreen()
|
|
|
{
|
|
|
CheckParts();
|
|
@@ -188,6 +229,7 @@ namespace InABox.DynamicGrid
|
|
|
{
|
|
|
if (MasterHeader != null)
|
|
|
MasterHeader.Content = MasterCaption;
|
|
|
+
|
|
|
if (DetailsHeader != null)
|
|
|
DetailsHeader.Content = DetailCaption;
|
|
|
|
|
@@ -199,22 +241,41 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
if (Grid != null)
|
|
|
{
|
|
|
- Grid.ColumnDefinitions[0].Width = View == DynamicSplitPanelView.Detail && Master != null
|
|
|
+ Grid.ColumnDefinitions[0].Width = (View == DynamicSplitPanelView.Detail)
|
|
|
+ && (Master != null)
|
|
|
+ && (IsViewAllowed(DynamicSplitPanelView.Combined,DynamicSplitPanelView.Master))
|
|
|
? new GridLength(1.0F, GridUnitType.Auto)
|
|
|
: new GridLength(0.0F, GridUnitType.Pixel);
|
|
|
- Grid.ColumnDefinitions[1].Width = Master == null ? new GridLength(0.0F, GridUnitType.Pixel) :
|
|
|
- View == DynamicSplitPanelView.Master ? new GridLength(1.0F, GridUnitType.Star) :
|
|
|
- View == DynamicSplitPanelView.Detail ? new GridLength(0.0F, GridUnitType.Pixel) :
|
|
|
- new GridLength(MasterWidth, GridUnitType.Pixel);
|
|
|
- Grid.ColumnDefinitions[2].Width = View == DynamicSplitPanelView.Combined && Master != null
|
|
|
+
|
|
|
+ Grid.ColumnDefinitions[1].Width = Master == null
|
|
|
+ ? new GridLength(0.0F, GridUnitType.Pixel)
|
|
|
+ : View switch {
|
|
|
+ DynamicSplitPanelView.Master => new GridLength(1.0F, GridUnitType.Star),
|
|
|
+ DynamicSplitPanelView.Detail => new GridLength(0.0F, GridUnitType.Pixel),
|
|
|
+ _ => Anchor == DynamicSplitPanelAnchor.Master
|
|
|
+ ? new GridLength(AnchorWidth, GridUnitType.Pixel)
|
|
|
+ : new GridLength(1.0F, GridUnitType.Star)
|
|
|
+ };
|
|
|
+
|
|
|
+ Grid.ColumnDefinitions[2].Width = (View == DynamicSplitPanelView.Combined)
|
|
|
+ && (Master != null)
|
|
|
? new GridLength(1.0F, GridUnitType.Auto)
|
|
|
: new GridLength(0.0F, GridUnitType.Pixel);
|
|
|
- Grid.ColumnDefinitions[3].Width = View == DynamicSplitPanelView.Master
|
|
|
- ? new GridLength(0.0F, GridUnitType.Star)
|
|
|
- : new GridLength(1.0F, GridUnitType.Star);
|
|
|
- Grid.ColumnDefinitions[4].Width = View == DynamicSplitPanelView.Master
|
|
|
+
|
|
|
+ Grid.ColumnDefinitions[3].Width = View switch
|
|
|
+ {
|
|
|
+ DynamicSplitPanelView.Master => new GridLength(0.0F, GridUnitType.Pixel),
|
|
|
+ DynamicSplitPanelView.Detail => new GridLength(1.0F, GridUnitType.Star),
|
|
|
+ _ => Anchor == DynamicSplitPanelAnchor.Detail
|
|
|
+ ? new GridLength(AnchorWidth, GridUnitType.Pixel)
|
|
|
+ : new GridLength(1.0F, GridUnitType.Star)
|
|
|
+ };
|
|
|
+
|
|
|
+ Grid.ColumnDefinitions[4].Width = (View == DynamicSplitPanelView.Master)
|
|
|
+ && (IsViewAllowed(DynamicSplitPanelView.Combined,DynamicSplitPanelView.Detail))
|
|
|
? new GridLength(1.0F, GridUnitType.Auto)
|
|
|
: new GridLength(0.0F, GridUnitType.Pixel);
|
|
|
+
|
|
|
Grid.RowDefinitions[0].Height =
|
|
|
Header == null ? new GridLength(0.0F, GridUnitType.Pixel) : new GridLength(1.0F, GridUnitType.Auto);
|
|
|
}
|
|
@@ -232,6 +293,22 @@ namespace InABox.DynamicGrid
|
|
|
SecondaryDetail == null ? new GridLength(0.0F, GridUnitType.Pixel) : new GridLength(1.0F, GridUnitType.Star);
|
|
|
DetailSplitter.IsEnabled = SecondaryDetail != null;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ if (CombinedRight != null)
|
|
|
+ {
|
|
|
+ CombinedRight.Visibility = (View == DynamicSplitPanelView.Combined) && IsViewAllowed(DynamicSplitPanelView.Master)
|
|
|
+ ? Visibility.Visible
|
|
|
+ : Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CombinedLeft != null)
|
|
|
+ {
|
|
|
+ CombinedLeft.Visibility = (View == DynamicSplitPanelView.Combined) && IsViewAllowed(DynamicSplitPanelView.Detail)
|
|
|
+ ? Visibility.Visible
|
|
|
+ : Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
@@ -241,14 +318,17 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
private void Splitter_PreviewMouseUp(object sender, MouseButtonEventArgs e)
|
|
|
{
|
|
|
- SetValue(MasterWidthProperty, Grid.ColumnDefinitions[1].ActualWidth);
|
|
|
+ if (Anchor == DynamicSplitPanelAnchor.Master)
|
|
|
+ SetValue(AnchorWidthProperty, Grid.ColumnDefinitions[1].ActualWidth);
|
|
|
+ else
|
|
|
+ SetValue(AnchorWidthProperty, Grid.ColumnDefinitions[3].ActualWidth);
|
|
|
SetValue(DetailHeightProperty, SecondaryDetail == null ? 0.0F : DetailGrid.RowDefinitions[0].ActualHeight);
|
|
|
Changed();
|
|
|
}
|
|
|
|
|
|
private void Changed()
|
|
|
{
|
|
|
- OnChanged?.Invoke(this, new DynamicSplitPanelChangedArgs { View = View, MasterWidth = MasterWidth, DetailHeight = DetailHeight });
|
|
|
+ OnChanged?.Invoke(this, new DynamicSplitPanelSettings { View = View, AnchorWidth = AnchorWidth, DetailHeight = DetailHeight });
|
|
|
}
|
|
|
|
|
|
public override void OnApplyTemplate()
|