|
先看一下效果吧
调用代码如下
第五步:绘制控件的模板样式
在绘制之前,先添加一个nuget上面的引用,搜索expression.drawing,然后添加下面的引用
再在generic文件里面引入命名空间
xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
再写样式之前的准备工作就准备完了,后面就是开始写模板样式了,下面是样式的代码和注释- <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
-
复制代码 里面有一个名为ProgressBarValueToPercentage的转换,直接添加一个类,然后代码就在下面到现在,样式部分就写完了,然后还要去后台代码里面实现具体的功能
第六步:实现后台代码功能
[code]public class CycleProgressBar : RangeBase{ <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
public bool IsIndeterminate <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
{ <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
get { return (bool)GetValue(IsIndeterminateProperty); } <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
set { SetValue(IsIndeterminateProperty, value); } <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
} <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
// Using a DependencyProperty as the backing store for IsIndeterminate. <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
This enables animation, styling, binding, etc... <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
public static readonly DependencyProperty IsIndeterminateProperty = <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
DependencyProperty.Register("IsIndeterminate", typeof(bool), typeof(CycleProgressBar), new PropertyMetadata(false)); <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
private FrameworkElement _track; <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
static CycleProgressBar() <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
{ <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
//这段代码是创建控件的时候自带的,不用管,代码的意思就是去找generic里面名为CycleProgressBar的样式, <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
//如果把这段代码删了,或者generic没有CycleProgressBar的样式,程序就会报错 <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
DefaultStyleKeyProperty.OverrideMetadata(typeof(CycleProgressBar), new FrameworkPropertyMetadata(typeof(CycleProgressBar))); <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
} <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
/// <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
/// 计算进度条的值 <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
/// <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
private void SetPartTrackValue() <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
{ <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
double minimum = this.Minimum; <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
double maximum = this.Maximum; <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
double value = this.Value; <local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
<local:ProgressBarValueToPercentage x:Key="ProgressBarValueToPercentage"/>
double num = (maximum |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|