Windows Phone 7的等待状态用五个移动的点呈现,在Win8中也使用了同样的风格,感觉很好,本人尝试制作了一个Silverlight控件模仿他,感觉效果还可以,发出来分享一下,有什么不足的地方请各位高手点评点评。
下面是进度条的效果截图
先上界面代码
View Code
Visible
Collapsed
Visible
Collapsed
Visible
Collapsed
Visible
Collapsed
Visible
Collapsed
接着是后台代码
View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication3
{
public partial class WP7ProgressBar : UserControl
{
public WP7ProgressBar()
{
InitializeComponent();
}
public void Start()
{
this.Visibility = Visibility.Visible;
Move.Begin();
}
public void Stop()
{
this.Visibility = Visibility.Collapsed;
Move.Stop();
}
public double MoveWidth
{
get { return (double)base.GetValue(MoveWidthProperty); }
set { base.SetValue(MoveWidthProperty, value); }
}
public static DependencyProperty MoveWidthProperty = DependencyProperty.Register(
"MoveWidth",
typeof(double ),
typeof(WP7ProgressBar),
new PropertyMetadata(0.0, new PropertyChangedCallback(WP7ProgressBar.OnMoveWidthPropertyChanged)));
private static void OnMoveWidthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
try
{
WP7ProgressBar wp7ProgressBar =(d as WP7ProgressBar);
wp7ProgressBar.SplineDoubleKeyFrame1.Value = (double)e.NewValue;
wp7ProgressBar.SplineDoubleKeyFrame2.Value = (double)e.NewValue;
wp7ProgressBar.SplineDoubleKeyFrame3.Value = (double)e.NewValue;
wp7ProgressBar.SplineDoubleKeyFrame4.Value = (double)e.NewValue;
wp7ProgressBar.SplineDoubleKeyFrame5.Value = (double)e.NewValue;
wp7ProgressBar.Width = (double)e.NewValue;
}
catch (Exception ex)
{
string ks = ex.ToString();
}
}
public new Brush Background
{
get { return (Brush)base.GetValue(BackgroundProperty); }
set { base.SetValue(BackgroundProperty, value); }
}
public new static DependencyProperty BackgroundProperty = DependencyProperty.Register(
"Background",
typeof(Brush),
typeof(WP7ProgressBar),
new PropertyMetadata(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), new PropertyChangedCallback(WP7ProgressBar.OnBackgroundPropertyChanged)));
private static void OnBackgroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
try
{
WP7ProgressBar wp7ProgressBar = (d as WP7ProgressBar);
wp7ProgressBar.BackCanvas.Background = (Brush)e.NewValue;
}
catch (Exception ex)
{
string ks = ex.ToString();
}
}
public new Brush PointColor
{
get { return (Brush)base.GetValue(PointColorProperty); }
set { base.SetValue(PointColorProperty, value); }
}
public new static DependencyProperty PointColorProperty = DependencyProperty.Register(
"PointColor",
typeof(Brush),
typeof(WP7ProgressBar),
new PropertyMetadata(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), new PropertyChangedCallback(WP7ProgressBar.OnPointColorPropertyChanged)));
private static void OnPointColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
try
{
WP7ProgressBar wp7ProgressBar = (d as WP7ProgressBar);
wp7ProgressBar.rectangle1 .Fill = (Brush)e.NewValue;
wp7ProgressBar.rectangle2.Fill = (Brush)e.NewValue;
wp7ProgressBar.rectangle3.Fill = (Brush)e.NewValue;
wp7ProgressBar.rectangle4.Fill = (Brush)e.NewValue;
wp7ProgressBar.rectangle5.Fill = (Brush)e.NewValue;
}
catch (Exception ex)
{
string ks = ex.ToString();
}
}
}
}
在Silverlight中声明属性感觉比较麻烦,大家有没有提高效率的方法,推荐推荐。 |