silverlight – DragAndDropSample 樣本

來源:互聯網
上載者:User

參考自: 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" }
                        };
        }
    }
}

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.