如题,在网上找的跑马灯自定义控件
ProgressControl.cs
......
using System.Windows.Threading;
namespace Marquee
{
[TemplatePart(Name = "PART_ContentHost", Type = typeof(ContentPresenter))]
public class ProgressControl: ContentControl
{
public int Loop
{
get { return (int)GetValue(LoopProperty); }
set { SetValue(LoopProperty, value); }
}
public static readonly DependencyProperty LoopProperty = DependencyProperty.Register(
"Loop",
typeof(int),
typeof(ProgressControl),
new FrameworkPropertyMetadata(0, OnMarqueeParameterChanged, OnCoerceLoop));
private static object OnCoerceLoop(DependencyObject sender, object value)
{
int loop = (int)value;
if (loop < 0)
{
throw new ArgumentException("Loop必须大于等于0");
}
return value;
}
/// <summary>
/// Gets/Sets the direction of the animation.
/// </summary>
public Direction Direction
{
get { return (Direction)GetValue(DirectionProperty); }
set { SetValue(DirectionProperty, value); }
}
public static readonly DependencyProperty DirectionProperty = DependencyProperty.Register(
"Direction",
typeof(Direction),
typeof(ProgressControl),
new FrameworkPropertyMetadata(Direction.Right, OnMarqueeParameterChanged));
/// <summary>
/// Gets/Sets The animation behavior.
/// </summary>
public MarqueeBehavior Behavior
{
get { return (MarqueeBehavior)GetValue(BehaviorProperty); }
set { SetValue(BehaviorProperty, value); }
}
public static readonly DependencyProperty BehaviorProperty = DependencyProperty.Register(
"Behavior",
typeof(MarqueeBehavior),
typeof(ProgressControl),
new FrameworkPropertyMetadata(MarqueeBehavior.Scroll, OnMarqueeParameterChanged));
public double ScrollAmount
{
get { return (double)GetValue(ScrollAmountProperty); }
set { SetValue(ScrollAmountProperty, value); }
}
public static readonly DependencyProperty ScrollAmountProperty = DependencyProperty.Register(
"ScrollAmount",
typeof(double),