fixed #441
This commit is contained in:
1 parent
c6763a4b10
commit
c6262c0ebd
4 files changed
+96
-23
No files matched your search
+27
-20
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
using HandyControl.Expression.Drawing;
|
using HandyControl.Expression.Drawing;
|
||||||
@@ -24,19 +23,32 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
public override void OnApplyTemplate()
|
public override void OnApplyTemplate()
|
||||||
{
|
{
|
||||||
|
if (_elementPanel != null)
|
||||||
|
{
|
||||||
|
_elementPanel.SizeChanged -= ElementPanel_SizeChanged;
|
||||||
|
}
|
||||||
|
|
||||||
base.OnApplyTemplate();
|
base.OnApplyTemplate();
|
||||||
|
|
||||||
_elementContent = GetTemplateChild(ElementContent) as FrameworkElement;
|
_elementContent = GetTemplateChild(ElementContent) as FrameworkElement;
|
||||||
_elementPanel = GetTemplateChild(ElementPanel) as Panel;
|
_elementPanel = GetTemplateChild(ElementPanel) as Panel;
|
||||||
|
|
||||||
|
if (_elementPanel != null)
|
||||||
|
{
|
||||||
|
_elementPanel.SizeChanged += ElementPanel_SizeChanged;
|
||||||
|
}
|
||||||
|
|
||||||
UpdateContent();
|
UpdateContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ElementPanel_SizeChanged(object sender, SizeChangedEventArgs e) => UpdateContent();
|
||||||
|
|
||||||
public static readonly DependencyProperty RunawayProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty RunawayProperty = DependencyProperty.Register(
|
||||||
"Runaway", typeof(bool), typeof(RunningBlock), new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.AffectsRender));
|
"Runaway", typeof(bool), typeof(RunningBlock), new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||||
|
|
||||||
public bool Runaway
|
public bool Runaway
|
||||||
{
|
{
|
||||||
get => (bool) GetValue(RunawayProperty);
|
get => (bool)GetValue(RunawayProperty);
|
||||||
set => SetValue(RunawayProperty, ValueBoxes.BooleanBox(value));
|
set => SetValue(RunawayProperty, ValueBoxes.BooleanBox(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +57,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
public bool AutoRun
|
public bool AutoRun
|
||||||
{
|
{
|
||||||
get => (bool) GetValue(AutoRunProperty);
|
get => (bool)GetValue(AutoRunProperty);
|
||||||
set => SetValue(AutoRunProperty, ValueBoxes.BooleanBox(value));
|
set => SetValue(AutoRunProperty, ValueBoxes.BooleanBox(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +66,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
public Orientation Orientation
|
public Orientation Orientation
|
||||||
{
|
{
|
||||||
get => (Orientation) GetValue(OrientationProperty);
|
get => (Orientation)GetValue(OrientationProperty);
|
||||||
set => SetValue(OrientationProperty, value);
|
set => SetValue(OrientationProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +75,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
public Duration Duration
|
public Duration Duration
|
||||||
{
|
{
|
||||||
get => (Duration) GetValue(DurationProperty);
|
get => (Duration)GetValue(DurationProperty);
|
||||||
set => SetValue(DurationProperty, value);
|
set => SetValue(DurationProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +84,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
public double Speed
|
public double Speed
|
||||||
{
|
{
|
||||||
get => (double) GetValue(SpeedProperty);
|
get => (double)GetValue(SpeedProperty);
|
||||||
set => SetValue(SpeedProperty, value);
|
set => SetValue(SpeedProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +105,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
public bool IsRunning
|
public bool IsRunning
|
||||||
{
|
{
|
||||||
get => (bool) GetValue(IsRunningProperty);
|
get => (bool)GetValue(IsRunningProperty);
|
||||||
set => SetValue(IsRunningProperty, ValueBoxes.BooleanBox(value));
|
set => SetValue(IsRunningProperty, ValueBoxes.BooleanBox(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,60 +114,57 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
public bool AutoReverse
|
public bool AutoReverse
|
||||||
{
|
{
|
||||||
get => (bool) GetValue(AutoReverseProperty);
|
get => (bool)GetValue(AutoReverseProperty);
|
||||||
set => SetValue(AutoReverseProperty, ValueBoxes.BooleanBox(value));
|
set => SetValue(AutoReverseProperty, ValueBoxes.BooleanBox(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateContent()
|
private void UpdateContent()
|
||||||
{
|
{
|
||||||
if (_elementContent == null || _elementPanel == null) return;
|
if (_elementContent == null || _elementPanel == null) return;
|
||||||
|
if (MathHelper.IsZero(_elementPanel.ActualWidth) || MathHelper.IsZero(_elementPanel.ActualHeight)) return;
|
||||||
|
|
||||||
_storyboard?.Stop();
|
_storyboard?.Stop();
|
||||||
|
|
||||||
_elementPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
|
||||||
_elementPanel.Width = _elementPanel.DesiredSize.Width;
|
|
||||||
_elementPanel.Height = _elementPanel.DesiredSize.Height;
|
|
||||||
|
|
||||||
double from;
|
double from;
|
||||||
double to;
|
double to;
|
||||||
PropertyPath propertyPath;
|
PropertyPath propertyPath;
|
||||||
|
|
||||||
if (Orientation == Orientation.Horizontal)
|
if (Orientation == Orientation.Horizontal)
|
||||||
{
|
{
|
||||||
if (AutoRun && _elementPanel.Width < ActualWidth)
|
if (AutoRun && _elementPanel.ActualWidth < ActualWidth)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Runaway)
|
if (Runaway)
|
||||||
{
|
{
|
||||||
from = -_elementPanel.Width;
|
from = -_elementPanel.ActualWidth;
|
||||||
to = ActualWidth;
|
to = ActualWidth;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
from = 0;
|
from = 0;
|
||||||
to = ActualWidth - _elementPanel.Width;
|
to = ActualWidth - _elementPanel.ActualWidth;
|
||||||
SetCurrentValue(AutoReverseProperty, ValueBoxes.TrueBox);
|
SetCurrentValue(AutoReverseProperty, ValueBoxes.TrueBox);
|
||||||
}
|
}
|
||||||
propertyPath = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)");
|
propertyPath = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (AutoRun && _elementPanel.Height < ActualHeight)
|
if (AutoRun && _elementPanel.ActualHeight < ActualHeight)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Runaway)
|
if (Runaway)
|
||||||
{
|
{
|
||||||
from = -_elementPanel.Height;
|
from = -_elementPanel.ActualHeight;
|
||||||
to = ActualHeight;
|
to = ActualHeight;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
from = 0;
|
from = 0;
|
||||||
to = ActualHeight - _elementPanel.Height;
|
to = ActualHeight - _elementPanel.ActualHeight;
|
||||||
SetCurrentValue(AutoReverseProperty, ValueBoxes.TrueBox);
|
SetCurrentValue(AutoReverseProperty, ValueBoxes.TrueBox);
|
||||||
}
|
}
|
||||||
propertyPath = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)");
|
propertyPath = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)");
|
||||||
@@ -180,7 +189,5 @@ namespace HandyControl.Controls
|
|||||||
_storyboard.Children.Add(animation);
|
_storyboard.Children.Add(animation);
|
||||||
_storyboard.Begin();
|
_storyboard.Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnRender(DrawingContext drawingContext) => UpdateContent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using HandyControl.Tools;
|
||||||
|
|
||||||
|
namespace HandyControl.Controls
|
||||||
|
{
|
||||||
|
public class RunningBorder : Border
|
||||||
|
{
|
||||||
|
private bool _test;
|
||||||
|
|
||||||
|
protected override Size MeasureOverride(Size constraint)
|
||||||
|
{
|
||||||
|
if (_test)
|
||||||
|
{
|
||||||
|
_test = false;
|
||||||
|
return constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
var child = Child;
|
||||||
|
var borderThickness = BorderThickness;
|
||||||
|
var padding = Padding;
|
||||||
|
|
||||||
|
if (UseLayoutRounding)
|
||||||
|
{
|
||||||
|
var dpiScaleX = DpiHelper.DeviceDpiX;
|
||||||
|
var dpiScaleY = DpiHelper.DeviceDpiY;
|
||||||
|
|
||||||
|
borderThickness = new Thickness(
|
||||||
|
DpiHelper.RoundLayoutValue(borderThickness.Left, dpiScaleX),
|
||||||
|
DpiHelper.RoundLayoutValue(borderThickness.Top, dpiScaleY),
|
||||||
|
DpiHelper.RoundLayoutValue(borderThickness.Right, dpiScaleX),
|
||||||
|
DpiHelper.RoundLayoutValue(borderThickness.Bottom, dpiScaleY));
|
||||||
|
}
|
||||||
|
|
||||||
|
var borderSize = ConvertThickness2Size(borderThickness);
|
||||||
|
var paddingSize = ConvertThickness2Size(padding);
|
||||||
|
var mySize = new Size();
|
||||||
|
|
||||||
|
if (child != null)
|
||||||
|
{
|
||||||
|
var combined = new Size(borderSize.Width + paddingSize.Width, borderSize.Height + paddingSize.Height);
|
||||||
|
var borderConstraint = new Size(Math.Max(0.0, constraint.Width - combined.Width), Math.Max(0.0, constraint.Height - combined.Height));
|
||||||
|
var childConstraint = new Size(Math.Max(0.0, double.PositiveInfinity - combined.Width), Math.Max(0.0, double.PositiveInfinity - combined.Height));
|
||||||
|
|
||||||
|
|
||||||
|
child.Measure(borderConstraint);
|
||||||
|
var childSize = child.DesiredSize;
|
||||||
|
|
||||||
|
mySize.Width = childSize.Width + combined.Width;
|
||||||
|
mySize.Height = childSize.Height + combined.Height;
|
||||||
|
|
||||||
|
child.Measure(childConstraint);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mySize = new Size(borderSize.Width + paddingSize.Width, borderSize.Height + paddingSize.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mySize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Size ConvertThickness2Size(Thickness th) => new Size(th.Left + th.Right, th.Top + th.Bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\TextBlockAttach.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\TextBlockAttach.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Base\AdornerElement.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Base\AdornerElement.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\FloatingBlock.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\FloatingBlock.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\RunningBlock\RunningBorder.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\SplitButton.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\SplitButton.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Carousel\CarouselItem.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Carousel\CarouselItem.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Dialog\DialogContainer.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Dialog\DialogContainer.cs" />
|
||||||
@@ -69,7 +70,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeTrack.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeTrack.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeThumb.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeThumb.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\TwoWayRangeBase.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\TwoWayRangeBase.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\RunningBlock.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\RunningBlock\RunningBlock.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Text\SimpleText.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Text\SimpleText.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Window\GlowWindow.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Window\GlowWindow.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Collections\DateTimeRangeComparer.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Collections\DateTimeRangeComparer.cs" />
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="hc:RunningBlock">
|
<ControlTemplate TargetType="hc:RunningBlock">
|
||||||
<Border CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" Padding="{TemplateBinding Padding}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
|
<hc:RunningBorder CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" Padding="{TemplateBinding Padding}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
|
||||||
<hc:SimplePanel ClipToBounds="True">
|
<hc:SimplePanel ClipToBounds="True">
|
||||||
<hc:SimplePanel HorizontalAlignment="Left" x:Name="PART_Panel">
|
<hc:SimplePanel HorizontalAlignment="Left" x:Name="PART_Panel">
|
||||||
<ContentPresenter x:Name="PART_ContentElement" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left">
|
<ContentPresenter x:Name="PART_ContentElement" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left">
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
</ContentPresenter>
|
</ContentPresenter>
|
||||||
</hc:SimplePanel>
|
</hc:SimplePanel>
|
||||||
</hc:SimplePanel>
|
</hc:SimplePanel>
|
||||||
</Border>
|
</hc:RunningBorder>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
|||||||
Reference in new issue
Block a user