Skip to content

Commit

Permalink
1.1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Mochengvia committed Jul 12, 2023
1 parent 078ec17 commit 9059335
Show file tree
Hide file tree
Showing 14 changed files with 498 additions and 201 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
using System;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Media3D;

namespace Panuon.WPF.UI.Internal
{
class TabControlPanel
: Panel
{
#region Properties

#region HeaderPanelAlignment
public TabControlHeaderPanelAlignment HeaderPanelAlignment
{
get { return (TabControlHeaderPanelAlignment)GetValue(HeaderPanelAlignmentProperty); }
set { SetValue(HeaderPanelAlignmentProperty, value); }
}

public static readonly DependencyProperty HeaderPanelAlignmentProperty =
DependencyProperty.Register("HeaderPanelAlignment", typeof(TabControlHeaderPanelAlignment), typeof(TabControlPanel), new FrameworkPropertyMetadata(TabControlHeaderPanelAlignment.Stretch, FrameworkPropertyMetadataOptions.AffectsArrange));
#endregion

#region Orientation
public Orientation Orientation
{
get { return (Orientation)GetValue(OrientationProperty); }
set { SetValue(OrientationProperty, value); }
}

public static readonly DependencyProperty OrientationProperty =
DependencyProperty.Register("Orientation", typeof(Orientation), typeof(TabControlPanel), new FrameworkPropertyMetadata(Orientation.Vertical, FrameworkPropertyMetadataOptions.AffectsArrange));
#endregion

#endregion

protected override Size MeasureOverride(Size constraint)
{
var width = 0d;
var height = 0d;
foreach (FrameworkElement child in Children)
{
child.Measure(constraint);
if (child is ScrollViewer scrollViewer)
{
var tabPanel = scrollViewer.Content as TabPanel;
tabPanel.Measure(constraint);
switch (Orientation)
{
case Orientation.Vertical:
height += tabPanel.DesiredSize.Height;
break;
case Orientation.Horizontal:
width += tabPanel.DesiredSize.Width;
break;
}
}
else
{
switch (Orientation)
{
case Orientation.Vertical:
height += child.DesiredSize.Height;
break;
case Orientation.Horizontal:
width += child.DesiredSize.Width;
break;
}
}
switch (Orientation)
{
case Orientation.Vertical:
width = Math.Max(width, child.DesiredSize.Width);
break;
case Orientation.Horizontal:
height = Math.Max(height, child.DesiredSize.Height);
break;
}
}

switch (Orientation)
{
case Orientation.Vertical:
return new Size(width, double.IsInfinity(constraint.Height)
? height
: constraint.Height);
default:
return new Size(double.IsInfinity(constraint.Width)
? width
: constraint.Width, height);
}
}

protected override Size ArrangeOverride(Size arrangeSize)
{
var ccFront = Children[0];
var bdrFront = Children[1];
var scrollViewer = (ScrollViewer)Children[2];
var bdrEnd = Children[3];
var ccEnd = Children[4];

switch (Orientation)
{
case Orientation.Vertical:
var contentHeight = (scrollViewer.Content as TabPanel).DesiredSize.Height;
SetCurrentValue(ContentWidthOrHeightProperty, contentHeight);

var top = 0d;
var scrollViewerHeight = Math.Max(0, arrangeSize.Height - ccFront.DesiredSize.Height - ccEnd.DesiredSize.Height);
if(contentHeight + ccFront.DesiredSize.Height + ccFront.DesiredSize.Height < arrangeSize.Height)
{
switch (HeaderPanelAlignment)
{
case TabControlHeaderPanelAlignment.Stretch:
break;
case TabControlHeaderPanelAlignment.Front:
scrollViewerHeight = Math.Min(scrollViewerHeight, contentHeight);
break;
case TabControlHeaderPanelAlignment.Center:
scrollViewerHeight = Math.Min(scrollViewerHeight, contentHeight);
top = (arrangeSize.Height - ccFront.DesiredSize.Height - scrollViewerHeight - ccEnd.DesiredSize.Height) / 2;
break;
case TabControlHeaderPanelAlignment.End:
scrollViewerHeight = Math.Min(scrollViewerHeight, contentHeight);
top = arrangeSize.Height - ccFront.DesiredSize.Height - scrollViewerHeight - ccEnd.DesiredSize.Height;
break;
}
}

ccFront.Arrange(new Rect(0, top, arrangeSize.Width, ccFront.DesiredSize.Height));
bdrFront.Arrange(new Rect(0, top, arrangeSize.Width, ccFront.DesiredSize.Height));
top += ccFront.DesiredSize.Height;

scrollViewer.Height = scrollViewerHeight;
scrollViewer.Arrange(new Rect(0, top, arrangeSize.Width, scrollViewerHeight));

top += scrollViewerHeight;
bdrEnd.Arrange(new Rect(0, top, arrangeSize.Width, ccEnd.DesiredSize.Height));
ccEnd.Arrange(new Rect(0, top, arrangeSize.Width, ccEnd.DesiredSize.Height));
break;
default:
var contentWidth = (scrollViewer.Content as TabPanel).DesiredSize.Width;
SetCurrentValue(ContentWidthOrHeightProperty, contentWidth);

var left = 0d;
var scrollViewerWidth = Math.Max(0, arrangeSize.Width - ccFront.DesiredSize.Width - ccEnd.DesiredSize.Width);

if (contentWidth + ccFront.DesiredSize.Width + ccFront.DesiredSize.Width < arrangeSize.Width)
{
switch (HeaderPanelAlignment)
{
case TabControlHeaderPanelAlignment.Stretch:
break;
case TabControlHeaderPanelAlignment.Front:
scrollViewerWidth = Math.Min(scrollViewerWidth, contentWidth);
break;
case TabControlHeaderPanelAlignment.Center:
scrollViewerWidth = Math.Min(scrollViewerWidth, contentWidth);
left = (arrangeSize.Width - ccFront.DesiredSize.Width - scrollViewerWidth - ccEnd.DesiredSize.Width) / 2;
break;
case TabControlHeaderPanelAlignment.End:
scrollViewerWidth = Math.Min(scrollViewerWidth, contentWidth);
left = arrangeSize.Width - ccFront.DesiredSize.Width - scrollViewerWidth - ccEnd.DesiredSize.Width;
break;
}
}

ccFront.Arrange(new Rect(left, 0, ccFront.DesiredSize.Width, arrangeSize.Height));
bdrFront.Arrange(new Rect(left, 0, ccFront.DesiredSize.Width, arrangeSize.Height));
left += ccFront.DesiredSize.Width;

scrollViewer.Width = scrollViewerWidth;
scrollViewer.Arrange(new Rect(left, 0, scrollViewerWidth, arrangeSize.Height));

left += scrollViewerWidth;
bdrEnd.Arrange(new Rect(left, 0, ccEnd.DesiredSize.Width, arrangeSize.Height));
ccEnd.Arrange(new Rect(left, 0, ccEnd.DesiredSize.Width, arrangeSize.Height));
break;
}

return arrangeSize;
}

public double ContentWidthOrHeight
{
get { return (double)GetValue(ContentWidthOrHeightProperty); }
set { SetValue(ContentWidthOrHeightProperty, value); }
}

public static readonly DependencyProperty ContentWidthOrHeightProperty =
DependencyProperty.Register("ContentWidthOrHeight", typeof(double), typeof(TabControlPanel));


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Globalization;
using System.Windows;

namespace Panuon.WPF.UI.Internal.Converters
{
class TabControlScrollButtonVisibilityConverter
: OneWayMultiValueConverterBase
{
public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var actualWidth = (double)values[0];
var containerWidth = (double)values[1];
var frontWidth = (double)values[2];
var endWidth = (double)values[3];
var contentWidth = containerWidth + frontWidth + endWidth;

if(contentWidth > actualWidth
&& Math.Abs(actualWidth - contentWidth) > 1)
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ class TabPanelMaxHeightConverter
{
public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var height = (double)values[0];
var alignment = (VerticalAlignment)values[1];
if(double.IsNaN(height) || alignment != VerticalAlignment.Stretch)
{
return double.PositiveInfinity;
}
var tabActualHeight = (double)values[2];
if (double.IsNaN(tabActualHeight))
{
return double.PositiveInfinity;
}
var frontHeight = (double)values[3];
var endHeight = (double)values[4];
return tabActualHeight - frontHeight - endHeight;
return Math.Max(0, tabActualHeight - frontHeight - endHeight);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Panuon.WPF.UI.Internal.Converters
{
class TabPanelMaxWidthConverter
class TabPanelMaxWidthConverter
: OneWayMultiValueConverterBase
{
public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var width = (double)values[0];
var height = (double)values[0];
var alignment = (HorizontalAlignment)values[1];
if(double.IsNaN(width) || alignment != HorizontalAlignment.Stretch)
if (double.IsNaN(height) || alignment != HorizontalAlignment.Stretch)
{
return double.PositiveInfinity;
}
Expand All @@ -22,7 +22,9 @@ public override object Convert(object[] values, Type targetType, object paramete
}
var frontWidth = (double)values[3];
var endWidth = (double)values[4];
return tabActualWidth - frontWidth - endWidth;
var backWidth = (double)values[5];
var foreWidth = (double)values[6];
return Math.Max(0, tabActualWidth - frontWidth - endWidth - backWidth - foreWidth);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\MessageBoxXWindow.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PendingBoxWindow.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\ScrollableControl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\TabControlPanel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\TimeSelectorItemPresenter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\Arc2Converter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\ArcConverter.cs" />
Expand Down Expand Up @@ -60,6 +61,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Converters\SliderTextLeftConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\StringNonnullAndNotEmptyToHiddenConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\StringNullOrEmptyToHiddenConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\TabControlScrollButtonVisibilityConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\ThicknessLeftRightOnlyConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\TransparentColorToBrushConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\ColorSelectorOpacitySliderBackgroundConverter.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static class ConverterKeys
public const string SliderTextLeftConverter = nameof(SliderTextLeftConverter);
public const string SliderTextTopConverter = nameof(SliderTextTopConverter);
public const string SwitchToggleMarginConverter = nameof(SwitchToggleMarginConverter);
public const string TabControlScrollButtonVisibilityConverter = nameof(TabControlScrollButtonVisibilityConverter);
public const string TabPanelMaxHeightConverter = nameof(TabPanelMaxHeightConverter);
public const string TabPanelMaxWidthConverter = nameof(TabPanelMaxWidthConverter);
public const string ThicknessLeftRightOnlyConverter = nameof(ThicknessLeftRightOnlyConverter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<icv:ComboBoxDropDownHorizontalOffsetConverter x:Key="{x:Static irs:ConverterKeys.ComboBoxDropDownHorizontalOffsetConverter}" />
<icv:ComboBoxDropDownMarginConverter x:Key="{x:Static irs:ConverterKeys.ComboBoxDropDownMarginConverter}" />
<icv:ComboBoxDropDownVerticalOffsetConverter x:Key="{x:Static irs:ConverterKeys.ComboBoxDropDownVerticalOffsetConverter}" />
<icv:TabControlScrollButtonVisibilityConverter x:Key="{x:Static irs:ConverterKeys.TabControlScrollButtonVisibilityConverter}" />
<icv:ContextMenuDropDownMarginConverter x:Key="{x:Static irs:ConverterKeys.ContextMenuDropDownMarginConverter}" />
<icv:DataGridSelectionUnitIsNotFullRowConverter x:Key="{x:Static irs:ConverterKeys.DataGridSelectionUnitIsNotFullRowConverter}" />
<icv:DisplayMemberPathPropertyValueConverter x:Key="{x:Static irs:ConverterKeys.DisplayMemberPathPropertyValueConverter}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:irs="clr-namespace:Panuon.WPF.UI.Internal.Resources">
<ResourceDictionary.MergedDictionaries>
<core:SharedResourceDictionary Source="pack://application:,,,/Panuon.WPF.UI;component/Styles/ButtonStyle.xaml" />
<core:SharedResourceDictionary Source="pack://application:,,,/Panuon.WPF.UI;component/Styles/RepeatButtonStyle.xaml" />
<core:SharedResourceDictionary Source="pack://application:,,,/Panuon.WPF.UI;component/Styles/TabItemStyle.xaml" />
<core:SharedResourceDictionary Source="pack://application:,,,/Panuon.WPF.UI;component/Templates/TabControlTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -34,6 +35,42 @@
Value="{Binding Path=(i:VisualStateHelper.Foreground), RelativeSource={RelativeSource AncestorType=TabItem}, Mode=OneWay}" />
</Style>

<Style x:Key="{ComponentResourceKey ResourceId=HeaderPanelScrollButtonStyleKey, TypeInTargetAssembly={x:Type local:TabControlHelper}}"
TargetType="RepeatButton"
BasedOn="{StaticResource {x:Static rs:StyleKeys.RepeatButtonStyle}}">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="local:RepeatButtonHelper.HoverBackground"
Value="{x:Null}" />
<Setter Property="local:RepeatButtonHelper.ClickBackground"
Value="{x:Null}" />
<Setter Property="FontFamily"
Value="/Panuon.WPF.UI;component/Resources/#PanuonIcon" />
<Style.Triggers>
<Trigger Property="Tag"
Value="Left">
<Setter Property="Content"
Value="&#xe901;" />
</Trigger>
<Trigger Property="Tag"
Value="Top">
<Setter Property="Content"
Value="&#xe902;" />
</Trigger>
<Trigger Property="Tag"
Value="Right">
<Setter Property="Content"
Value="&#xe903;" />
</Trigger>
<Trigger Property="Tag"
Value="Bottom">
<Setter Property="Content"
Value="&#xe904;" />
</Trigger>
</Style.Triggers>
</Style>


<Style x:Key="{x:Static rs:StyleKeys.TabControlStyle}"
TargetType="TabControl">
<Setter Property="i:VisualStateHelper.Regist"
Expand All @@ -50,6 +87,8 @@
Value="{Binding IsMouseOver, RelativeSource={RelativeSource Self}, Mode=OneWay}" />
<Setter Property="i:VisualStateHelper.IsSelected"
Value="{Binding IsSelected, RelativeSource={RelativeSource Self}, Mode=OneWay}" />
<Setter Property="local:TabControlHelper.CanHeaderPanelScroll"
Value="True" />
<Setter Property="local:TabControlHelper.HeaderPanelBackground"
Value="{Binding Background, RelativeSource={RelativeSource Self}, Mode=OneWay}" />
<Setter Property="local:TabControlHelper.HeaderPanelRibbonLineBrush"
Expand Down Expand Up @@ -96,6 +135,8 @@
Value="Collapsed" />
<Setter Property="local:TabControlHelper.RemoveButtonStyle"
Value="{StaticResource {ComponentResourceKey ResourceId=RemoveButtonStyleKey, TypeInTargetAssembly={x:Type local:TabControlHelper}}}" />
<Setter Property="local:TabControlHelper.HeaderPanelScrollButtonStyle"
Value="{StaticResource {ComponentResourceKey ResourceId=HeaderPanelScrollButtonStyleKey, TypeInTargetAssembly={x:Type local:TabControlHelper}}}" />
<Setter Property="VerticalContentAlignment"
Value="Stretch" />
<Setter Property="HorizontalContentAlignment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
BorderThickness="{Binding Path=(i:VisualStateHelper.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
</Grid>
<Border x:Name="BdrContainer"
Height="{TemplateBinding BoxHeight}"
Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}, Mode=OneWay}"
HorizontalAlignment="Right">
<Border.Margin>
Expand Down
Loading

0 comments on commit 9059335

Please sign in to comment.