[转]WPF——Thumb
2024-10-07 22:48:37
Thumb类,表示可由用户拖动的控件。其主要三个事件分别DragDelta,DragStarted,DragCompleted.
DragDelta——当 Thumb 控件具有逻辑焦点和鼠标捕获时,随着鼠标位置更改发生一次或多次。
DragStarted——在 Thumb 控件接收逻辑焦点和鼠标捕获时发生。
DragCompleted——在 Thumb 控件失去鼠标捕获时发生。
1 <Window.Resources>
2 <ResourceDictionary>
3 <ControlTemplate x:Key="template1">
4 <Ellipse Width="60" Height="30">
5 <Ellipse.Fill>
6 <SolidColorBrush Color="Black"></SolidColorBrush>
7 </Ellipse.Fill>
8 </Ellipse>
9 </ControlTemplate>
10 </ResourceDictionary>
11 </Window.Resources>
12
13 <Canvas Name="myCanvas">
14 <Thumb Name="myThumb" DragDelta="onDragDelta" Background="Blue" DragStarted="myThumb_DragStarted" DragCompleted="myThumb_DragCompleted"
15 Canvas.Left="0" Canvas.Top="0" Width="200" Height="200"/>
16
17 <!--Template="{StaticResource template1}",若此处采用此种方法为Thumb绑定模版,是无法通过DragStarted,DragCompleted事件来改变其背景的-->
18 </Canvas>
1 void onDragDelta(object sender, DragDeltaEventArgs e)
2 {
3 Canvas.SetLeft(myThumb, Canvas.GetLeft(myThumb) + e.HorizontalChange);
4
5 Canvas.SetTop(myThumb, Canvas.GetTop(myThumb) + e.VerticalChange);
6
7 }
8
9 private void myThumb_DragStarted(object sender, DragStartedEventArgs e)
10 {
11 myThumb.Background = Brushes.Orange;
12 }
13
14 private void myThumb_DragCompleted(object sender, DragCompletedEventArgs e)
15 {
16 myThumb.Background = Brushes.Blue;
17 }
最新文章
- New Year&#39;s resolution for 2016
- C#创建socket服务
- 大话设计模式C++版——抽象工厂模式
- AngularJs定制样式插入到ueditor中的问题总结
- <;a>;标签跳转传值。
- android xutils
- static inline
- BootStrap table 传递搜索参数
- DEDE栏目内容调用
- thinkphp批量删除的实现
- python中逐行读取文件的最佳方式_Drupal_新浪博客
- iOS开发讯飞语音的集成
- fmt标签格式化数字和时间
- PHP 工厂模式 实例讲解
- Python 实现接口类的两种方式+邮件提醒+动态导入模块+反射(参考Django中间件源码)
- iOS中蓝牙的使用
- jeecg字典表—普通表
- DG搭建方式区分
- “全栈2019”Java多线程第三十四章:超时自动唤醒被等待的线程
- React Native(三)——推送jpush-react-native