原文地址http://www.windowsphonegeek.com/articles/WP7-PerformanceProgressBar-in-depth
今天想研究一下WP7进度条的使用,进度条是Silverlight for Windows Phone toolkit提供的一个组件,就是5个点滚动显示的进度条效果,很多应用都使用了,用法下面说的很明白了,我也懒得翻译了。
by WindowsPhoneGeek
In this post I am going to talk about the PerformanceProgressBar from the
Silverlight for Windows Phone toolkit in depth.
NOTE: Previously we covered all controls from the WP7 toolkit in a series of :
21 WP7 Toolkit in Depth articles covering all controls. So now it is time for a follow up. In the latest
Feb 2011 update of the toolkit along with some fixes two new controls were added : PerformanceProgressbar and TiltEffect.
Basically PerformanceProgressBar is an animated indeterminate progress bar, which is used in situations where the extent of the task is unknown or the progress of the task cannot be determined in a way that could be expressed as a percentage or similar.
This bar uses animated dots to show that progress is taking place, rather than using the size of the filled portion to show the total amount of progress. It is actually the well known PerformanceProgressBar provided by
Jeff Wilcox, which uses the compositor thread exclusively for animation, instead of the UI (user interface) thread.
PerformanceProgressBar
is a kind of progress bar implementation for a smoother appearance of the indeterminate states, with the added behavior that after the behavior is no longer needed, it smoothly fades out the dots for a less jarring experience. No exposed Value property. Important
- this control is not intended for regular progress bar use, but only indeterminate. As a result, only an IsIndeterminate set of visual states are defined in the nested progress bar template. Use the standard
ProgressBar control in the platform for determinate scenarios as there is no performance benefit in determinate mode. For example it can be very useful when implementing animated splash screen.
NOTE: One of the reasons that this is so important is that performance is always an issue when there is a progress bar visible (whether you're parsing data, processing layout changes, or performing network requests), so any issues with bogging down
the user interface thread will be more obvious.
NOTE: PerformanceProgressBar is different from the standard
ProgressBar. There is an unfortunate performance issue with the default way the PerformanceBar is constructed in the WP7 SDK. To achieve the effect of the dots flying across the screen the standard control actually uses 5 slider controls (where the thumb
of the slider is actually styled to be the dots). This generates a lot of work for the UI thread, when in actual fact we want to off load tasks such as animation to the Compositor thread where ever possible and leave the UI thread for things like layout passes
and our application logic. (reference:Tips for ProgressBar Performance in WP7).
VisualStructure
NOTE:
PerformanceProgressBar derives from Control and its ControlTemplate consists of a customized ProgressBar with some additional elements so that it fits in the Metro UI concept.
NOTE: The RelativeAnimatingContentControl which is in the default ControlTemplate is a very special primitive control that works around a limitation in the core animation subsystem of Silverlight: there is no way to declare in VSM states relative
properties, such as animating from 0 to 33% the width of the control, using double animations for translation.
It's a tough problem to solve property, but this primitive, unsupported control does offer a solution based on magic numbers that still allows a designer to make alterations to their animation values to present their vision for custom templates. This is
instrumental in offering a Windows Phone ProgressBar implementation that uses the render thread instead of animating UI thread-only properties. This control is not supported other than that it is used by the performance progress bar control. It should not
be used elsewhere!
Key Properties
This is a dependency property of type bool. It gets or sets the value indicating whether the actual indeterminate property should be reflecting a particular value.
This is a dependency property of type bool. It gets or sets a value indicating whether the control is in the indeterminate state.
Sample Usage
To begin using PerformanceProgressBar first add a reference to the Microsoft.Phone.Controls.Toolkit.dll assembly which is installed with the toolkit and you can find it in :
C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Toolkit\Feb11\Bin\ Microsoft.Phone.Controls.Toolkit.dll.
To use the PerformanceProgressBar in the XAML you will have to add the following namespace declaration ("toolkit" prefix declaration):
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
Here is an example of how to use a PerformanceProgressBar declared in XAML. We will use a ChackBox to show/hide the progress bar (the IsIndeterminate is bound to the IsChecked).
1
2
|
< CheckBox
Content = "Show PerformanceProgressBar"
IsChecked = "{Binding IsIndeterminate, ElementName=performanceProgressBar, Mode=TwoWay}" />
< toolkit:PerformanceProgressBar
x:Name = "performanceProgressBar" />
|
NOTE: For more info about the ElementBinding check this post:
WP7 Element Binding samples
You can declare a PerformanceProgressBar in code behind as well:
1
2
3
4
5
6
7
|
private
void btnGenerate_Click( object
sender, RoutedEventArgs e)
{
ProgressBar bar =
new ProgressBar();
bar.IsIndeterminate =
true ;
this .ContentPanel.Children.Add(bar);
}
|
NOTE: The property responsible for the color of the animation effect is "Foreground"!
1
|
< toolkit:PerformanceProgressBar
x:Name = "performanceProgressBarCustomized"
Foreground = "Red"
Background = "Red"
IsIndeterminate = "True" />
|
That was all about the
Silverlight for Windows Phone 7 Toolkit PerformanceProgressBar in depth. The full source code can be downloaded here:
I hope that the article was helpful.
分享到:
相关推荐
从项目里面提取出来的一个等待进度条 用到的就下载吧,自己运行过了 肯定没问题
使用WPF实现仿wp8加载进度条动画效果
wp7工具集,xap12安装器,taskviewer任务查看器,AdvancedExplorer资源浏览器,WP7Booster优化器,wp7sdk_mini
wp7三星i8350刷机工具,不会用啊,有会用的大侠介绍一下啊。。
国内最新的wp7游戏程序部署工具,简单大气的界面可以与微软的zune相媲美,使用起来却比zune方便多了。这个最新版的轻量级的工具可以方便地搜索、下载和拖曳的方式部署任何的.xap程序。只要你的wp7手机是破解了的,就...
“传智播客.Net培训WP7模拟器”(20110417版)的优点如下: 1)可以运行在windows xp下 2)实现了WP7绝大部分API。包括启动器、选择器、外设(收音机、GPS、振动器、麦克风、摄像头、加速度感应器)、WP7特殊控件...
此SDK是精简版本的WIN7 WP7 SDK工具,仅2.8M。没有实用工具,部署可用 TOM
怎样把一个wp7的工程迁移到wp8上怎样把一个wp7的工程迁移到wp8上
wp7高级编程中文版,有助于爱好wp7开发者,轻松学习,好好看吧
ZTE N880E WP7驱动,刷wp7必备驱动
WP7查询IP所在地
这个是一个WP7 下载文件的源码,windows phone不提供浏览目录的功能,所以想在程序里写浏览并上传的同学,放弃这个想法吧。我也走了很多弯路,才知道。 另外声明下:小弟传了一个Windows Phone 7高级编程中文版的,...
wp7截图工具
wp7手机软件,可以把wp7手机变成U盘,解压后直接打开。
ChevronWP7 破解 WP7 中文版,比较好。大家试试看吧。
一个小WP7计算器加点小地图,试上传。Wp7,看好的是未来。
developer.force.com的api开发入门说明白皮书,英文版
一个wp7后台线程实现的实例,可用vs2010直接打开,供wp7开发者参考
WP7 3Mktplace v0.6.4,可以下载WP市场的所有免费或收费的应用。 下载后可以破解收费软件。
WP7 codeproject app .zip