wpf TelerikUI使用DragDropManager

首先,我先創建事務對象ApplicationInfo,當暴露出一對屬性當例子集合對于構成ListBoxes。這個類在例子中顯示如下代碼:
?

public class ApplicationInfo 
{ public Double Price { get; set; } public String IconPath { get; set; } public String Name { get; set; } public String Author { get; set; } public static ObservableCollection<ApplicationInfo> GenerateApplicationInfos() { ObservableCollection<ApplicationInfo> result = new ObservableCollection<ApplicationInfo>(); ApplicationInfo info1 = new ApplicationInfo(); info1.Name = "Large Collider"; info1.Author = "C.E.R.N."; info1.IconPath = @"img/Atom.png"; result.Add(info1); ApplicationInfo info2 = new ApplicationInfo(); info2.Name = "Paintbrush"; info2.Author = "Imagine Inc."; info2.IconPath = @"img/Brush.png"; result.Add(info2); ApplicationInfo info3 = new ApplicationInfo(); info3.Name = "Lively Calendar"; info3.Author = "Control AG"; info3.IconPath = @"img/CalendarEvents.png"; result.Add(info3); ApplicationInfo info4 = new ApplicationInfo(); info4.Name = "Fire Burning ROM"; info4.Author = "The CD Factory"; info4.IconPath = @"img/CDBurn.png"; result.Add(info4); ApplicationInfo info5 = new ApplicationInfo(); info5.Name = "Fav Explorer"; info5.Author = "Star Factory"; info5.IconPath = @"img/favorites.png"; result.Add(info5); ApplicationInfo info6 = new ApplicationInfo(); info6.Name = "IE Fox"; info6.Author = "Open Org"; info6.IconPath = @"img/Connected.png"; result.Add(info6); ApplicationInfo info7 = new ApplicationInfo(); info7.Name = "Charting"; info7.Author = "AA-AZ inc"; info7.IconPath = @"img/ChartDot.png"; result.Add(info7); ApplicationInfo info8 = new ApplicationInfo(); info8.Name = "SuperPlay"; info8.Author = "EB Games"; info8.IconPath = @"img/Games.png"; result.Add(info8); return result; } 
} 

然后需要定義ListBoxes對于符合的ItemTemplates。我同樣啟動拖動ListBoxItems和允許拖動每一個ListBoxes

<Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <Style TargetType="ListBoxItem"> <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True"></Setter> </Style> <DataTemplate x:Key="ApplicationTemplate"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding IconPath}"/> <TextBlock Margin="5" Text="{Binding Name}" VerticalAlignment="Center"></TextBlock> </StackPanel> </DataTemplate> </Grid.Resources> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <ListBox x:Name="ApplicationList" ItemTemplate="{StaticResource ApplicationTemplate}" AllowDrop="True"/> <ListBox x:Name="MyAppList" Background="Gray" Grid.Column="1"   ItemTemplate="{StaticResource ApplicationTemplate}" AllowDrop="True"/> 
</Grid> 

之后我們需要設置控件的ItemSource:

ApplicationList.ItemsSource = ApplicationInfo.GenerateApplicationInfos(); 
MyAppList.ItemsSource = new ObservableCollection<ApplicationInfo>(); 

附加拖動處理事件

DragDropManager.AddDragInitializeHandler(ApplicationList, OnDragInitialize); 
DragDropManager.AddDragInitializeHandler(MyAppList, OnDragInitialize); DragDropManager.AddGiveFeedbackHandler(ApplicationList, OnGiveFeedback); 
DragDropManager.AddGiveFeedbackHandler(MyAppList, OnGiveFeedback); DragDropManager.AddDragDropCompletedHandler(ApplicationList, OnDragCompleted); 
DragDropManager.AddDragDropCompletedHandler(MyAppList, OnDragCompleted); DragDropManager.AddDropHandler(ApplicationList, OnDrop); 
DragDropManager.AddDropHandler(MyAppList, OnDrop);   

然后在DraInitialize定義數據當拖動后,同時呈現。同樣設置了DragDropEffects到所有允許拖動的場景

private void OnDragInitialize(object sender, DragInitializeEventArgs args) 
{ args.AllowedEffects = DragDropEffects.All; var payload = DragDropPayloadManager.GeneratePayload(null); var data = ((FrameworkElement)args.OriginalSource).DataContext; payload.SetData("DragData", data); args.Data = payload; args.DragVisual = new ContentControl { Content = data, ContentTemplate = LayoutRoot.Resources["ApplicationTemplate"] as DataTemplate }; 
} 

同樣設置鼠標光標為箭頭:
?

private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs args) 
{ args.SetCursor(Cursors.Arrow); args.Handled = true; 
} 

最后添加邏輯,將在拖動后允許完成操作:
?

private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args) 
{ var data = ((DataObject)args.Data).GetData("DragData"); ((IList)(sender as ListBox).ItemsSource).Add(data); 
} public void OnDragCompleted(object sender, Telerik.Windows.DragDrop.DragDropCompletedEventArgs args) 
{ var data = DragDropPayloadManager.GetDataFromObject(args.Data, "DragData"); ((IList)(sender as ListBox).ItemsSource).Remove(data); 
} 

拖動如下ListBoxes

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/215651.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/215651.shtml
英文地址,請注明出處:http://en.pswp.cn/news/215651.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

亞馬遜S3V4驗簽與MINIO驗簽區別

1、先看下官方文檔 AWS S3V4 DEMO 2、實際調用試試 1&#xff09;代碼 // 計算auth// for a simple GET, we have no body so supply the precomputed empty hashMap<String, String> headers new HashMap<String, String>();headers.put("x-amz-content…

0013Java安卓程序設計-ssm酒品移動電商平臺app

文章目錄 **摘要**目錄系統實現5.1 APP端5.2管理員功能模塊開發環境 編程技術交流、源碼分享、模板分享、網課分享 企鵝&#x1f427;裙&#xff1a;776871563 摘要 首先,論文一開始便是清楚的論述了系統的研究內容。其次,剖析系統需求分析,弄明白“做什么”,分析包括業務分析…

Firewalld 防火墻配置

文章目錄 Firewalld 防火墻配置1. Firewalld 概述2. 區域名稱及策略規則3. Firewalld 配置方法4. Firewalld 參數和命令5. Firewalld 兩種模式6. Firewalld 使用 Firewalld 防火墻配置 1. Firewalld 概述 firewalld 是一個動態防火墻管理器&#xff0c;作為 Systemd 管理的防…

【docker】常用命令

啟動docker服務 systemctl start docker 停止docker服務 systemctl stop docker 重啟docker服務 systemctl restart docker 查看docker服務狀態 systemctl status docker 設置開機啟動docker服務 systemctl enable docker 設置關閉開機啟動docker服務 systemctl disable …

數據在內存中的存儲(浮點型篇)

1.例子&#xff1a;5.5&#xff1a;內存存儲為101.1&#xff0c;十分位百分位依次為2的-1次方&#xff0c;2的-2次方&#xff0c;而使用科學計數法可以改寫為1.011*2的2次方 2.國際標準公式&#xff1a;-1的D次方*M*2的E次方&#xff0c;x1負0正 3.M在存儲時默認整數部分為1&…

使用Spring Boot和領域驅動設計實現模塊化整體

用模塊化整體架構編寫的代碼實際上是什么樣的&#xff1f;借助 Spring Boot 和 DDD&#xff0c;我們踏上了編寫可維護和可演化代碼的旅程。 當談論模塊化整體代碼時&#xff0c;我們的目標是以下幾點&#xff1a; 應用程序被組織成模塊。每個模塊解決業務問題的不同部分。模塊…

springcloud微服務篇--1.認識微服務

一、服務架構演變。 單體架構&#xff1a; 將業務的所有功能集中在一個項目中開發&#xff0c;打成一個包部署。 優點&#xff1a;架構簡單 &#xff0c;部署成本低。 缺點&#xff1a;耦合度高 分布式架構 根據業務功能對系統進行拆分&#xff0c;每個業務模塊作為獨立項…

[idea]idea連接clickhouse23.6.2.18

一、安裝驅動 直接在pom.xml加上那個lz4也是必要的不然會報錯 <dependency><groupId>com.clickhouse</groupId><artifactId>clickhouse-jdbc</artifactId><version>0.4.2</version></dependency><dependency><group…

歌唱比賽計分 (8 分)設有10名歌手(編號為1-10)參加歌詠比賽

未采用結構體的解法&#xff0c;通過二維數組解題 #include <stdio.h> void rank(int arr[10][6] ) { int str[4] { 0 }; int a1[6] { 0 }; int k 0; int i 0; int z 0; int j 0; int temp 0; double s1[10][2] { 0 }; dou…

(1)mysql容器化部署

mysql容器化部署&#xff1a; 數據持久化&#xff08;方便數據保存及遷移&#xff09;: 需要持久化兩個目錄: 創建/mysql (1)mysql配置文件: /mysql/mysql-cnf/my.cnf vim my.cnf [mysqld] pid-file /var/run/mysqld/mysqld.pid socket /var/run/mysqld/…

【51單片機系列】使用74HC595控制數碼管顯示

使用74HC595結合數碼管顯示字符。 proteus仿真設計如下&#xff0c;74HC595的輸出端連接到動態數碼管的位選和靜態數碼管的段選&#xff0c;動態數碼管的段選連接到P0口。這兩個數碼管都是共陰極的。 靜態數碼管顯示字符0-F&#xff0c;軟件設計如下&#xff1a; /*實現功能&a…

Java:SpringBoot獲取當前運行的環境activeProfile

代碼示例 /*** 啟動監聽器*/ Component public class AppListener implements ApplicationListener<ApplicationReadyEvent> {Overridepublic void onApplicationEvent(ApplicationReadyEvent event) {// 獲取當前的環境&#xff0c;如果是test&#xff0c;則直接返回Co…

redis實際應用實現合集

一、redis實現搶紅包的功能&#xff08;set 數據結構&#xff09; 分兩種情況&#xff1a; 情況一: 從10個觀眾中隨機抽2名幸運觀眾 首先需要把10個觀眾的id&#xff08;具體是什么id可以根據實際業務情況自己定義&#xff09;放到redis 的 set 集合里 然后隨機抽取2名幸運…

【hcie-cloud】【8】華為云Stack_LLD設計【部署設計、資源設計、服務設計、學習推薦、縮略語】【下】

設計概覽、整體架構設計、網絡設計 看下面-這篇文章 【hcie-cloud】【7】華為云Stack_LLD設計【設計概覽、整體架構設計、網絡設計、部署設計、資源設計、服務設計】【上】 部署設計 云平臺整體部署架構 圖中在Region下每個灰底都代表一個數據中心&#xff0c;AZ1可以跨數據…

yarn系統架構與安裝

1.1 YARN系統架構 YARN的基本思想是將資源管理和作業調度/監視功能劃分為單獨的守護進程。其思想是擁有一個全局ResourceManager (RM)&#xff0c;以及每個應用程序擁有一個ApplicationMaster (AM)。應用程序可以是單個作業&#xff0c;也可以是一組作業。 一個ResourceManage…

ai智能機器人外呼系統怎么操作?

什么是ai智能機器人外呼&#xff1f;ai智能機器人外呼怎么操作&#xff1f;當下&#xff0c;很多企業主已經認識到&#xff0c;AI外呼是一種高效的拉新引流手段。但具體到實際應用中&#xff0c;實現的效果好像并沒有那么理想。從企業外呼的結果來看&#xff0c;接通率是可以達…

【信息安全】-ISO/IEC 27001-2022(翻譯)

文章目錄 范圍規范性引用文件3 術語和定義4 組織環境&#xff08;P&#xff09;4.1 理解組織及其環境4.2 理解相關方的需求和期望組織應確定:a) 信息安全管理體系相關方;b) 這些相關方的相關要求;c) 哪些要求可以通過信息安全管理體系得到解決。注:相關方的要求可包括法律、法規…

Ceph入門到精通-ceph二次開發開源協議考慮

Ceph 是一個開源的分布式存儲系統&#xff0c;它由多個組件組成&#xff0c;包括分布式對象存儲&#xff08;RADOS&#xff09;、分布式塊存儲&#xff08;RBD&#xff09;和分布式文件系統&#xff08;CephFS&#xff09;等。Ceph 采用了 GNU Lesser General Public License&a…

kuboard如何部署nacos?

? kuboard如何部署nacos&#xff1f; 這個快速開始手冊是幫忙您快速在您的電腦上&#xff0c;下載、安裝并使用 Nacos。 項目包含一個可構建的Nacos Docker Image&#xff0c;旨在利用StatefulSets在Kubernetes上部署Nacos。 在高級使用中,Nacos在K8S擁有自動擴容縮容和數據…