WPF中进度条同步实现
WPF界面的编写
滑动条的显示
//前台界面的设计
<Border Grid.Row="1"
Background="Transparent"
BorderThickness="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="18" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBlock Margin="26,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="12"
FontWeight="Regular"
Foreground="#333333"
Text="笔触大小" />
<Slider x:Name="slider1"
Grid.Row="1"
Height="18"
Margin="26,0,10,0"
aps:ThumbBehaviors.DragCompletedCommand="{Binding DragedCompletedCommand}"
aps:ThumbBehaviors.DragStartedCommand="{Binding DragedStartedCommand}"
//移动范围只能是整数
IsSnapToTickEnabled="True"
//绑定最大值"笔触大小的值"
Maximum="{Binding MaxPenWidth}"
Minimum="1"
Style="{DynamicResource SliderStyleMax}"
Value="{Binding PenWidth, Mode=TwoWay}" />
<StackPanel Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Right"
Orientation="Horizontal">
<TextBlock Margin="0,0,26,0"
FontSize="12"
//text的值 使用ElementName绑定数据 这个数据使用的是"Slider"控件且采用名字去别名
Text="{Binding ElementName=slider1, Path=Value}" />
</StackPanel>
</Grid>
</Border>
与滑动条同步的画笔大小
<Grid x:Name="mouseGrid"
//涂抹的画笔大小
Width="{Binding PenWidth}"
Height="{Binding PenWidth}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Visibility="Collapsed">
<Grid.Effect>
<DropShadowEffect Opacity="0.4"
ShadowDepth="-1"
Color="#333333" />
</Grid.Effect>
<Ellipse HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Stroke="#333333"
//定义边框粗细
StrokeThickness="{Binding Scale, Converter={StaticResource StrokeConverter}}" />
</Grid>
相关属性的使用
- 画笔大小的设置
//画笔默认是初始值是15
private double penWidth = 15;
public double PenWidth {
get {
return penWidth;
}
set {
Set(ref penWidth, value);
OnDragDelta?.Invoke();
}
} - ?. :是在C#6.0中才有的,这个也称为空值传播运算,这个运算可以确保在事件没有订阅是不引发事件的
- OnDragDelta?.Invoke();中的OnDragDelta,是在最开始进行封装了"public event Action OnDragDelta;"
- 画笔最大值属性的设置
private int maxPenWidth;
public int MaxPenWidth {
get {
return maxPenWidth;
}
set {
Set(ref maxPenWidth, value);
PenWidth = value * 0.2;
}
}- Scale属性可以通过鼠标,加与减相关命令来控制画笔大小
private double scale = 1.0;
public double Scale {
get {
return scale;
}
set {
Set(ref scale, value);
}
}- 相关控制的命令
private RelayCommand reduceVisualCommand = null;
public RelayCommand ReduceVisualCommand {
get {
return reduceVisualCommand ?? new RelayCommand(() => {
double targetScale = Math.Round(Scale - 0.1, 1);
if (targetScale < 0.4) {
targetScale = 0.4;
}
Scale = targetScale;
});
}
} private RelayCommand<int> mouseWheelCommand = null;
public RelayCommand<int> MouseWheelCommand {
get {
return mouseWheelCommand ?? new RelayCommand<int>((delta) => {
double targetScale = Scale + delta * 0.001;
if (targetScale > 10.0) {
targetScale = 10.0;
}
if (targetScale < 0.4) {
targetScale = 0.4;
}
Scale = targetScale;
});
}
} private RelayCommand addVisualCommand = null;
public RelayCommand AddVisualCommand {
get {
return addVisualCommand ?? new RelayCommand(() => {
double targetScale = Math.Round(Scale + 0.1, 1);
if (targetScale > 10.0) {
targetScale = 10.0;
}
Scale = targetScale;
});
}
}
WPF中进度条同步实现的更多相关文章
- WPF的进度条progressbar,运行时间elapse time和等待spinner的实现
今天用.NET 4.5中的TPL的特性做了个小例子,实现了WPF的进度条progressbar,运行时间elapse time和等待spinner. 先上图吧. 这个例子包含4个实现,分别是同步版 ...
- wpf 导出Excel Wpf Button 样式 wpf简单进度条 List泛型集合对象排序 C#集合
wpf 导出Excel 1 private void Button_Click_1(object sender, RoutedEventArgs e) 2 { 3 4 ExportDataGrid ...
- AFHTTPSessionManager下载文件 及下载中 进度条处理,进度条处理需要特别注意,要加载NSRunLoop 中
1.下载文件 和进度条处理代码 - (void)timer:(NSTimer *)timer{ // 另一个View中 进度条progress属性赋值 _downloadView.progress = ...
- Jsf中进度条的用法
Jsf中进度条的用法 前端页面 <!-- 进度条 --> <p:progressBar widgetVar="pbAjax" ajax="true&qu ...
- WPF 自定义进度条
WPF设计界面过程中,有时需要设计一种可以手动滑动修改并实时显示的进度条 进度条,效果如下: 颜色.图标.节点什么的,都可以重新替换. 前端XAML代码: <UserControl x:Clas ...
- WPF 水平进度条
WPF设计界面过程中,有时需要设计一种可以手动滑动修改并实时显示的进度条 进度条,效果如下: 颜色.图标.节点什么的,都可以重新替换. 前端XAML代码: <UserControl x:Clas ...
- 关于C# WinForm中进度条的实现方法
http://www.cnblogs.com/Sue_/articles/2024932.html 进度条是一个软件人性化考虑之一,他给用户的感觉就是程序内部在不停的动作,执行到了什么程度,而不是整个 ...
- wpf 水波进度条 用户控件
之前看公司web前端做了个 圆形的水波纹 进度条,就想用wpf 做一个,奈何自己太菜 一直做不出来,在看过 “普通的地球人” 的 “ WPF实现三星手机充电界面 博客之后 我也来照葫芦画个瓢. 废话不 ...
- QT中进度条的使用
在QT中可以用QProgressBar或着QProgressDialog来实现进度条. QProgressBar的使用 首先在designer中拖一个按钮和进度条部件,按下面初始化 //补充:下面两句 ...
- WPF 简易进度条效果
最近做一个项目,看到以前同事写的进度条效果不错,所以,拿来简化了下,不炫,但是项目中还是够用的. 还是,先来看下调用以后的效果 1.因为ProgressbBar的Foreground显示不得不一样,所 ...
随机推荐
- LeetCode 周赛 338,贪心 / 埃氏筛 / 欧氏线性筛 / 前缀和 / 二分查找 / 拓扑排序
本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 提问. 大家好,我是小彭. 上周末是 LeetCode 第 338 场周赛,你参加了吗?这场周赛覆盖的知识点很多,第 ...
- pandas之设置显示格式
在用 Pandas 做数据分析的过程中,总需要打印数据分析的结果,如果数据体量较大就会存在输出内容不全(部分内容省略)或者换行错误等问题.Pandas 为了解决上述问题,允许你对数据显示格式进行设置. ...
- cf1809e(edu145e)
1 /* 2 _ooOoo_ 3 o8888888o 4 88" . "88 5 (| -_- |) 6 O\ = /O 7 ____/`---'\____ 8 .' \\| |/ ...
- day18:json模块&time模块&zipfile模块
json模块 1.关于json的定义 所有的编程语言都能够识别的数据格式叫做json,是字符串能够通过json序列化成字符串与如下类型: (int float bool str list tuple ...
- day17:内置方法&math模块&random模块&pickle模块
内置方法 1.round:四舍五入 正常遵守四舍五入,但在n.5结构中,n为偶数则舍去,n为奇数则进一. res1 = round(4.51) # 5 res2 = round(4.5) # 4 re ...
- django中使用celery,模拟商品秒杀。
Celery是Python开发的简单.灵活可靠的.处理大量消息的分布式任务调度模块 安装: pip install celery # 安装celery库 pip install redis # cel ...
- 随手记:linux校准时间
记录一下校准时间操作的执行步骤: 首先使用 date 查看当前时间是否准确 校准时间命令 ntpdate cn.pool.ntp.org 如果没有权限: sudo -i 会出现输入密码,直接输入密码即 ...
- Yii初学者必看-yii 表单验证规则
对yii深入了解总结出:希望对初学者有些帮助 Active Record (AR) 是一个流行的 对象-关系映射 (ORM) 技术. 每个 AR 类代表一个数据表(或视图),数据表(或视图)的列在 A ...
- 使用Python代码远程连接服务器
目录 一.paramiko模块的介绍 二.基本使用(用户名密码登录) 三.用公钥私钥连接 一.paramiko模块的介绍 模块介绍 使用Python的第三方模块paramiko实现远程连接服务器 功能 ...
- Linux操作系统网络模块
Linux操作系统的网络模块是负责网络通信的核心部分.它通过实现各种协议和算法,使得计算机能够在网络中进行数据交换和通信.网络模块主要包括以下几个方面的功能: (1)IP协议栈:负责处理网络层的数据包 ...