This commit is contained in:
NaBian committed 2020-06-03 23:41:14 +08:00
1 parent 8b6fd84a8b
commit 7648f20605
4 files changed
+60 -68

No files matched your search

@@ -9,6 +9,8 @@
<StackPanel Margin="32" VerticalAlignment="Center">
<hc:RunningBlock Content="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}"/>
<hc:RunningBlock Runaway="False" Content="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}" Margin="0,16,0,0"/>
<hc:RunningBlock HorizontalAlignment="Left" Width="500" Speed="50" Content="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}" Margin="0,16,0,0"/>
<hc:RunningBlock HorizontalAlignment="Left" Width="300" FontSize="30" Speed="50" Content="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}" Margin="0,16,0,0"/>
<hc:RunningBlock HorizontalAlignment="Left" AutoRun="True" Width="100" Runaway="False" Content="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}" Duration="0:0:2" Margin="0,16,0,0"/>
<hc:RunningBlock HorizontalAlignment="Left" AutoReverse="True" AutoRun="True" Width="100" Content="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}" Margin="0,16,0,0"/>
<hc:RunningBlock HorizontalAlignment="Left" AutoRun="True" Width="200" Content="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}" Margin="0,16,0,0"/>
@@ -4,6 +4,7 @@ using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using HandyControl.Data;
using HandyControl.Expression.Drawing;
namespace HandyControl.Controls
{
@@ -65,6 +66,15 @@ namespace HandyControl.Controls
set => SetValue(DurationProperty, value);
}
public static readonly DependencyProperty SpeedProperty = DependencyProperty.Register(
"Speed", typeof(double), typeof(RunningBlock), new FrameworkPropertyMetadata(double.NaN, FrameworkPropertyMetadataOptions.AffectsRender));
public double Speed
{
get => (double) GetValue(SpeedProperty);
set => SetValue(SpeedProperty, value);
}
public static readonly DependencyProperty IsRunningProperty = DependencyProperty.Register(
"IsRunning", typeof(bool), typeof(RunningBlock), new PropertyMetadata(ValueBoxes.TrueBox, (o, args) =>
{
@@ -150,11 +160,18 @@ namespace HandyControl.Controls
propertyPath = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)");
}
var animation = new DoubleAnimation(from, to, Duration)
var duration = double.IsNaN(Speed)
? Duration
: !MathHelper.IsVerySmall(Speed)
? TimeSpan.FromSeconds((to - from) / Speed)
: Duration;
var animation = new DoubleAnimation(from, to, duration)
{
RepeatBehavior = RepeatBehavior.Forever,
AutoReverse = AutoReverse
};
Storyboard.SetTargetProperty(animation, propertyPath);
Storyboard.SetTarget(animation, _elementContent);
@@ -163,10 +180,6 @@ namespace HandyControl.Controls
_storyboard.Begin();
}
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
UpdateContent();
}
protected override void OnRender(DrawingContext drawingContext) => UpdateContent();
}
}
@@ -17,14 +17,16 @@
<Setter.Value>
<ControlTemplate TargetType="controls:RunningBlock">
<Border CornerRadius="{Binding Path=(controls:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" Padding="{TemplateBinding Padding}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
<controls:SimplePanel HorizontalAlignment="Left" x:Name="PART_Panel" ClipToBounds="True">
<ContentPresenter x:Name="PART_ContentElement" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left">
<ContentPresenter.RenderTransform>
<TransformGroup>
<TranslateTransform/>
</TransformGroup>
</ContentPresenter.RenderTransform>
</ContentPresenter>
<controls:SimplePanel ClipToBounds="True">
<controls:SimplePanel HorizontalAlignment="Left" x:Name="PART_Panel">
<ContentPresenter x:Name="PART_ContentElement" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left">
<ContentPresenter.RenderTransform>
<TransformGroup>
<TranslateTransform/>
</TransformGroup>
</ContentPresenter.RenderTransform>
</ContentPresenter>
</controls:SimplePanel>
</controls:SimplePanel>
</Border>
</ControlTemplate>
@@ -37,15 +37,12 @@ namespace HandyControl.Tools.Converter
{
if (source == null) throw GetConvertFromException(null);
switch (source)
return source switch
{
case string s:
return FromString(s, cultureInfo);
case double d:
return new ColLayout((int)d);
default:
return new ColLayout(Convert.ToInt32(source, cultureInfo));
}
string s => FromString(s, cultureInfo),
double d => new ColLayout((int) d),
_ => new ColLayout(Convert.ToInt32(source, cultureInfo))
};
}
[SecurityCritical]
@@ -108,53 +105,31 @@ namespace HandyControl.Tools.Converter
i++;
}
switch (i)
return i switch
{
case 1:
return new ColLayout(lengths[0]);
case 2:
return new ColLayout
{
Xs = lengths[0],
Sm = lengths[1]
};
case 3:
return new ColLayout
{
Xs = lengths[0],
Sm = lengths[1],
Md = lengths[2]
};
case 4:
return new ColLayout
{
Xs = lengths[0],
Sm = lengths[1],
Md = lengths[2],
Lg = lengths[3]
};
case 5:
return new ColLayout
{
Xs = lengths[0],
Sm = lengths[1],
Md = lengths[2],
Lg = lengths[3],
Xl = lengths[4]
};
case 6:
return new ColLayout
{
Xs = lengths[0],
Sm = lengths[1],
Md = lengths[2],
Lg = lengths[3],
Xl = lengths[4],
Xxl = lengths[5]
};
}
throw new FormatException("InvalidStringColLayout");
1 => new ColLayout(lengths[0]),
2 => new ColLayout {Xs = lengths[0], Sm = lengths[1]},
3 => new ColLayout {Xs = lengths[0], Sm = lengths[1], Md = lengths[2]},
4 => new ColLayout {Xs = lengths[0], Sm = lengths[1], Md = lengths[2], Lg = lengths[3]},
5 => new ColLayout
{
Xs = lengths[0],
Sm = lengths[1],
Md = lengths[2],
Lg = lengths[3],
Xl = lengths[4]
},
6 => new ColLayout
{
Xs = lengths[0],
Sm = lengths[1],
Md = lengths[2],
Lg = lengths[3],
Xl = lengths[4],
Xxl = lengths[5]
},
_ => throw new FormatException("InvalidStringColLayout")
};
}
}
}