silverlight - DragAndDropSample 示例

参考自: http://www.cnblogs.com/chenkai/archive/2010/05/26/1744226.html#1876533  and

http://www.silverlight.net/content/samples/sl4/toolkitcontrolsamples/run/default.html

xmal

< UserControl  x:Class ="System.Windows.Controls.Samples.DragAndDropSample"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable
="d"
    xmlns:win
="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    xmlns:controls
="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:controlsToolkit
="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:chartingToolkit
="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:layoutToolkit
="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
    
>
    
    
< Grid  x:Name ="LayoutRoot"  Background ="White" >
        
< Grid.RowDefinitions >
            
< RowDefinition  Height ="20" />
            
< RowDefinition  Height ="400" />
        
</ Grid.RowDefinitions >
        
< Grid.ColumnDefinitions >
            
< ColumnDefinition  Width ="400" />
            
< ColumnDefinition  Width ="400" />
        
</ Grid.ColumnDefinitions >

        
< TextBlock  Text ="All Employees"  Margin ="0,0,262,0"  Width ="138"   />
        
< controlsToolkit:ListBoxDragDropTarget  Grid.Column ="0"  Grid.Row ="1"  AllowDrop ="True"  HorizontalContentAlignment ="Stretch"  VerticalContentAlignment ="Stretch"  x:Name ="first" >
            
< ListBox  x:Name ="fromListBox"  SelectionMode ="Extended"   DisplayMemberPath ="Name"  Height ="396"  Width ="396" >
                
< ListBox.ItemsPanel >
                    
< ItemsPanelTemplate >
                        
< StackPanel  Orientation ="Vertical" />
                    
</ ItemsPanelTemplate >
                
</ ListBox.ItemsPanel >           
            
</ ListBox >
        
</ controlsToolkit:ListBoxDragDropTarget >

        
< TextBlock  Text ="Organization Hierarchy"  Grid.Column ="1"  Grid.Row ="0" />

        
< controlsToolkit:ListBoxDragDropTarget  Grid.Column ="1"  Grid.Row ="1"  AllowDrop ="true"  HorizontalContentAlignment ="Stretch"  VerticalContentAlignment ="Stretch"  x:Name ="two" >
            
< ListBox  x:Name ="fromListBox1"  SelectionMode ="Extended"   DisplayMemberPath ="Name"  Height ="396"  Width ="396" >
                
< ListBox.ItemsPanel >
                    
< ItemsPanelTemplate >
                        
< StackPanel  Orientation ="Vertical" />
                    
</ ItemsPanelTemplate >
                
</ ListBox.ItemsPanel >
            
</ ListBox >
        
</ controlsToolkit:ListBoxDragDropTarget >
        
< Button  Content ="Button"  Grid.RowSpan ="2"  Height ="23"  HorizontalAlignment ="Left"  Margin ="208,0,0,0"  Name ="button1"  VerticalAlignment ="Top"  Width ="75"  Click ="button1_Click"   />
    
</ Grid >
</ UserControl >

 

c#

using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Net;
using  System.Windows;
using  System.Windows.Controls;
using  System.Windows.Documents;
using  System.Windows.Input;
using  System.Windows.Media;
using  System.Windows.Media.Animation;
using  System.Windows.Shapes;
using  System.Collections.ObjectModel;

namespace  System.Windows.Controls.Samples
{
    
public   partial   class  DragAndDropSample : UserControl
    {
        
public  DragAndDropSample()
        {
            InitializeComponent();
            fromListBox.ItemsSource 
=  PersonDataProvider.GetData();
        }

        
private   void  button1_Click( object  sender, RoutedEventArgs e)
        {
            ItemCollection tc 
=  fromListBox1.Items;
        }
    }

    
public   class  Person
    {
        
private   string  name;

        
public   string  Name
        {
            
get  {  return  name; }
            
set  { name  =  value; }
        }
    }

    
public   class  PersonDataProvider
    {
        
public   static  ObservableCollection < Person >  GetData()
        {
            
return   new  ObservableCollection < Person >
                        {
                            
new  Person { Name  =   " Akash Sharma "  },
                            
new  Person { Name  =   " Vinay Sen "  },
                            
new  Person { Name  =   " Lalit Narayan "  },
                            
new  Person { Name  =   " Madhumita Chatterjee "  },
                            
new  Person { Name  =   " Priyanka Patil "  },
                            
new  Person { Name  =   " Kumar Sanu "  }
                        };
        }
    }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值