#715 – 在Canvas中使用Thumb控件实现拖动目标的功能(Using the Thumb Control to Drag Objects on a Canvas)
2017-06-05 18:44
696 查看
原文地址:https://wpf.2000things.com/2012/12/19/715-using-the-thumb-control-to-drag-objects-on-a-canvas/
你可以使用Thumb 控件在Canvas 上实现简单的拖动控件功能。设置Thumb 控件的Template
,使Template 包含你需要拖动的控件,然后在DragDelta 事件中处理。
下面的例子,在Canvas 面板中包含了三个控件,每一个都被包裹在了Thumb 控件中并且可以被拖动。
<Canvas>
<Thumb Canvas.Left="10" Canvas.Top="20" Canvas.ZIndex="99" DragDelta="Thumb_DragDelta">
<Thumb.Template>
<ControlTemplate>
<Image Width="60" Height="60" Source="Crown.jpg"/>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb Canvas.Left="100" Canvas.Top="60" DragDelta="Thumb_DragDelta">
<Thumb.Template>
<ControlTemplate>
<Image Width="80" Height="100" Source="HenryII.jpg"/>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb Canvas.Left="30" Canvas.Top="180" DragDelta="Thumb_DragDelta">
<Thumb.Template>
<ControlTemplate>
<Label Content="Westminster, 19-Dec-1154"/>
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Canvas>
在Thumb 控件的DragDelta 事件处理函数中,设置控件的位置:
你可以使用Thumb 控件在Canvas 上实现简单的拖动控件功能。设置Thumb 控件的Template
,使Template 包含你需要拖动的控件,然后在DragDelta 事件中处理。
下面的例子,在Canvas 面板中包含了三个控件,每一个都被包裹在了Thumb 控件中并且可以被拖动。
<Canvas>
<Thumb Canvas.Left="10" Canvas.Top="20" Canvas.ZIndex="99" DragDelta="Thumb_DragDelta">
<Thumb.Template>
<ControlTemplate>
<Image Width="60" Height="60" Source="Crown.jpg"/>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb Canvas.Left="100" Canvas.Top="60" DragDelta="Thumb_DragDelta">
<Thumb.Template>
<ControlTemplate>
<Image Width="80" Height="100" Source="HenryII.jpg"/>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb Canvas.Left="30" Canvas.Top="180" DragDelta="Thumb_DragDelta">
<Thumb.Template>
<ControlTemplate>
<Label Content="Westminster, 19-Dec-1154"/>
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Canvas>
在Thumb 控件的DragDelta 事件处理函数中,设置控件的位置:
相关文章推荐
- How to use toolbar control on dialog using CToolBar class in VC++ - VC++ 中用CToolBar 类如何使用ToolBar控件
- 【功能】C# 控件实现内容拖动(DragDrop)功能(SamWang)
- How to enumerate the system fonts in the combobox control using VC++ - 用VC++如何在ComboBox控件中枚举系统字体
- iOS Mobile Development: Using Xcode Targets to Reuse the Code 使用xcode targets来实现代码复用
- Using the viewport meta tag to control layout on mobile browsers
- #481 – 在InkCanvas 上使用鼠标绘图(You Can Draw On an InkCanvas Control with the Mouse)
- 使用ASP.NET AJAX Control Toolkit中的ReorderList控件实现用鼠标拖动改变条目顺序
- 如何解决使用ViewDragHelper,实现可拖动控件时,控件不能拖动和不能监听问题?
- #489 – 使用InkCanvas 进行手势识别(Using the InkCanvas to Recognize Gestures)
- 使用ControlToolkit中的控件实现用鼠标拖动
- #375 – 将Tooltip 于父控件的某个属性绑定(Binding Something in a Tooltip to a Property on the Parent Control)
- using Bash script to control LED with WiringPi on Raspberry Pi
- 使用CTabCtrl控件实现属性页功能
- 使用HorizontalScrollView实现水平控件拖动效果
- How to capture video frames from the camera as images using AV Foundation on iOS
- Using the VirtualBox to work on the old software
- javascript+canvas实现Go To The Moon小游戏
- ABP PUT、DELETE请求错误405.0 - Method Not Allowed 因为使用了无效方法(HTTP 谓词) 引发客户端错误 No 'Access-Control-Allow-Origin' header is present on the requested resource
- Atlas学习手记(7):使用DragOverlayExtender实现拖放功能
- [Angular] Scrolling the Message List To the Bottom Automatically Using OnChanges