有谁知道Toolkit:PanelDragDropTarget怎么用么

fanshaoer 2011-05-24 09:26:59

private UIElement dragedob;
private void DragLayout_ItemDragStarting(object sender, ItemDragEventArgs e)
{
this.TreePanel.Children.Remove(sender as UIElement);
dragedob = sender as UIElement;

}

private void DragLayout_ItemDroppedOnTarget(object sender, ItemDragEventArgs e)
{
this.TreePanel.UpdateLayout();
this.Destinetionpanel.Children.Add(dragedob);//
//e.RemoveDataFromDragSource();
}
...全文
207 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanshaoer 2011-06-03
  • 打赏
  • 举报
回复
谢谢冷帅哥!!
jv9 2011-05-24
  • 打赏
  • 举报
回复
在Silverlight Toolkit中有实例代码参考,DropDrag。


<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->

<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: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">
<StackPanel>
<ContentControl Content="Drag and drop employees between any two controls." Style="{StaticResource Header}"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="400"/>
<RowDefinition Height="400"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="400"/>
</Grid.ColumnDefinitions>

<TextBlock Text="All Employees" Grid.Column="0" Grid.Row="0" Style="{StaticResource Description}"/>
<controlsToolkit:ListBoxDragDropTarget Grid.Column="0" Grid.Row="1" AllowDrop="true" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox x:Name="fromListBox" SelectionMode="Extended" DisplayMemberPath="Name">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</controlsToolkit:ListBoxDragDropTarget>

<TextBlock Text="Organization Hierarchy" Grid.Column="1" Grid.Row="0" Style="{StaticResource Description}"/>
<controlsToolkit:TreeViewDragDropTarget Grid.Column="1" Grid.Row="1" AllowDrop="true" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<controlsToolkit:TreeViewDragDropTarget.Resources>
<win:HierarchicalDataTemplate x:Key="hierarchicalTemplate" ItemsSource="{Binding Reports}">
<TextBlock Text="{Binding Name}"/>
</win:HierarchicalDataTemplate>
</controlsToolkit:TreeViewDragDropTarget.Resources>
<controls:TreeView x:Name="treeView" ItemTemplate="{StaticResource hierarchicalTemplate}"/>
</controlsToolkit:TreeViewDragDropTarget>


<chartingToolkit:DataPointSeriesDragDropTarget Grid.Column="0" Grid.Row="2" AllowDrop="true" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<chartingToolkit:Chart x:Name="bugsChart" Title="Employee Bug Counts">
<chartingToolkit:ColumnSeries IndependentValueBinding="{Binding Name}" DependentValueBinding="{Binding AssignedBugs}" Title="Assigned Bugs"/>
<chartingToolkit:ColumnSeries IndependentValueBinding="{Binding Name}" DependentValueBinding="{Binding ResolvedBugs}" Title="Resolved Bugs"/>
</chartingToolkit:Chart>
</chartingToolkit:DataPointSeriesDragDropTarget>


<chartingToolkit:DataPointSeriesDragDropTarget Grid.Column="1" Grid.Row="2" AllowDrop="true" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<chartingToolkit:Chart x:Name="salaryChart" Title="Employee Salaries">
<chartingToolkit:PieSeries IndependentValueBinding="{Binding Name}" DependentValueBinding="{Binding Salary}" Title="Salary"/>
</chartingToolkit:Chart>
</chartingToolkit:DataPointSeriesDragDropTarget>
</Grid>
</StackPanel>
</UserControl>




// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using Microsoft.Windows;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Controls.DataVisualization.Charting;
using System.Linq;
namespace System.Windows.Controls.Samples
{
///<summary>
/// A sample that demonstrates the use of the drag and drop functionality
/// in the Silverlight Toolkit.
///</summary>
[Sample("Drag and Drop", DifficultyLevel.Advanced, "Drag and Drop")]
public partial class DragAndDropSample : UserControl
{
///<summary>
/// Flattens a tech employee.
///</summary>
///<param name="techEmployee">The tech employee.</param>
///<returns>A list including the tech employee and all reports.</returns>
private IEnumerable<TechEmployee> FlattenTechEmployee(TechEmployee techEmployee)
{
yield return techEmployee;
foreach (TechEmployee employee in techEmployee.Reports.SelectMany(emp => FlattenTechEmployee(emp)))
{
yield return employee;
}
}

///<summary>
/// Initializes a new instance of the DragAndDropSample class.
///</summary>
public DragAndDropSample()
{
InitializeComponent();

treeView.ItemsSource = TechEmployee.AllTechEmployees;

ObservableCollection<TechEmployee> allEmployees = new ObservableCollection<TechEmployee>();

foreach (TechEmployee employee in TechEmployee.AllTechEmployees.SelectMany(emp => FlattenTechEmployee(emp)))
{
allEmployees.Add(employee);
}

fromListBox.ItemsSource = allEmployees;

ObservableCollection<TechEmployee> bugsCollection = new ObservableCollection<TechEmployee>();
(bugsChart.Series[0] as DataPointSeries).ItemsSource = bugsCollection;
(bugsChart.Series[1] as DataPointSeries).ItemsSource = bugsCollection;
(salaryChart.Series[0] as DataPointSeries).ItemsSource = new ObservableCollection<TechEmployee>();
}
}
}

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧