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.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Expression.Drawing;
|
||||
@@ -24,19 +23,32 @@ namespace HandyControl.Controls
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
if (_elementPanel != null)
|
||||
{
|
||||
_elementPanel.SizeChanged -= ElementPanel_SizeChanged;
|
||||
}
|
||||
|
||||
base.OnApplyTemplate();
|
||||
|
||||
_elementContent = GetTemplateChild(ElementContent) as FrameworkElement;
|
||||
_elementPanel = GetTemplateChild(ElementPanel) as Panel;
|
||||
|
||||
if (_elementPanel != null)
|
||||
{
|
||||
_elementPanel.SizeChanged += ElementPanel_SizeChanged;
|
||||
}
|
||||
|
||||
UpdateContent();
|
||||
}
|
||||
|
||||
private void ElementPanel_SizeChanged(object sender, SizeChangedEventArgs e) => UpdateContent();
|
||||
|
||||
public static readonly DependencyProperty RunawayProperty = DependencyProperty.Register(
|
||||
"Runaway", typeof(bool), typeof(RunningBlock), new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public bool Runaway
|
||||
{
|
||||
get => (bool) GetValue(RunawayProperty);
|
||||
get => (bool)GetValue(RunawayProperty);
|
||||
set => SetValue(RunawayProperty, ValueBoxes.BooleanBox(value));
|
||||
}
|
||||
|
||||
@@ -45,7 +57,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public bool AutoRun
|
||||
{
|
||||
get => (bool) GetValue(AutoRunProperty);
|
||||
get => (bool)GetValue(AutoRunProperty);
|
||||
set => SetValue(AutoRunProperty, ValueBoxes.BooleanBox(value));
|
||||
}
|
||||
|
||||
@@ -54,7 +66,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
get => (Orientation) GetValue(OrientationProperty);
|
||||
get => (Orientation)GetValue(OrientationProperty);
|
||||
set => SetValue(OrientationProperty, value);
|
||||
}
|
||||
|
||||
@@ -63,7 +75,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public Duration Duration
|
||||
{
|
||||
get => (Duration) GetValue(DurationProperty);
|
||||
get => (Duration)GetValue(DurationProperty);
|
||||
set => SetValue(DurationProperty, value);
|
||||
}
|
||||
|
||||
@@ -72,7 +84,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public double Speed
|
||||
{
|
||||
get => (double) GetValue(SpeedProperty);
|
||||
get => (double)GetValue(SpeedProperty);
|
||||
set => SetValue(SpeedProperty, value);
|
||||
}
|
||||
|
||||
@@ -93,7 +105,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public bool IsRunning
|
||||
{
|
||||
get => (bool) GetValue(IsRunningProperty);
|
||||
get => (bool)GetValue(IsRunningProperty);
|
||||
set => SetValue(IsRunningProperty, ValueBoxes.BooleanBox(value));
|
||||
}
|
||||
|
||||
@@ -102,60 +114,57 @@ namespace HandyControl.Controls
|
||||
|
||||
public bool AutoReverse
|
||||
{
|
||||
get => (bool) GetValue(AutoReverseProperty);
|
||||
get => (bool)GetValue(AutoReverseProperty);
|
||||
set => SetValue(AutoReverseProperty, ValueBoxes.BooleanBox(value));
|
||||
}
|
||||
|
||||
private void UpdateContent()
|
||||
{
|
||||
if (_elementContent == null || _elementPanel == null) return;
|
||||
if (MathHelper.IsZero(_elementPanel.ActualWidth) || MathHelper.IsZero(_elementPanel.ActualHeight)) return;
|
||||
|
||||
_storyboard?.Stop();
|
||||
|
||||
_elementPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
_elementPanel.Width = _elementPanel.DesiredSize.Width;
|
||||
_elementPanel.Height = _elementPanel.DesiredSize.Height;
|
||||
|
||||
double from;
|
||||
double to;
|
||||
PropertyPath propertyPath;
|
||||
|
||||
if (Orientation == Orientation.Horizontal)
|
||||
{
|
||||
if (AutoRun && _elementPanel.Width < ActualWidth)
|
||||
if (AutoRun && _elementPanel.ActualWidth < ActualWidth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Runaway)
|
||||
{
|
||||
from = -_elementPanel.Width;
|
||||
from = -_elementPanel.ActualWidth;
|
||||
to = ActualWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
from = 0;
|
||||
to = ActualWidth - _elementPanel.Width;
|
||||
to = ActualWidth - _elementPanel.ActualWidth;
|
||||
SetCurrentValue(AutoReverseProperty, ValueBoxes.TrueBox);
|
||||
}
|
||||
propertyPath = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AutoRun && _elementPanel.Height < ActualHeight)
|
||||
if (AutoRun && _elementPanel.ActualHeight < ActualHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Runaway)
|
||||
{
|
||||
from = -_elementPanel.Height;
|
||||
from = -_elementPanel.ActualHeight;
|
||||
to = ActualHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
from = 0;
|
||||
to = ActualHeight - _elementPanel.Height;
|
||||
to = ActualHeight - _elementPanel.ActualHeight;
|
||||
SetCurrentValue(AutoReverseProperty, ValueBoxes.TrueBox);
|
||||
}
|
||||
propertyPath = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)");
|
||||
@@ -180,7 +189,5 @@ namespace HandyControl.Controls
|
||||
_storyboard.Children.Add(animation);
|
||||
_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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user