我们正在尝试弄清楚如何将项目从LibraryStack容器拖到ScatterView上,就像照片查看器示例应用程序的工作方式一样。目前,项目只是在我们将其拖出后飞回LibraryStack。我们可以将项目拖放到其他LibraryStacks或LibraryBars中。
以下是我们正在尝试的示例:
<s:SurfaceWindow x:Class="Idia_seminar.SurfaceWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.microsoft.com/surface/2008"
Title="Idia_seminar"
>
<s:SurfaceWindow.Resources>
<ImageBrush x:Key="WindowBackground" Stretch="None" Opacity="0.6" ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/>
</s:SurfaceWindow.Resources>
<Grid Background="{StaticResource WindowBackground}" >
<s:ScatterView Name="scatterView1" AllowDrop="True">
<s:SurfaceButton Name="surfaceButton1">Button</s:SurfaceButton>
<s:LibraryStack AllowDrop="True">
<s:LibraryStackItem Content="hello"></s:LibraryStackItem>
</s:LibraryStack>
</s:ScatterView>
</Grid>
</s:SurfaceWindow>谢谢!
发布于 2010-03-17 18:22:12
这当然是可行的。我编写了一个示例,允许您从散点视图中的库栏中拖动项目,并将项目拖放到散点视图中,这些项目将显示为新的散点视图。
我不确定你哪里出错了,但是为了让拖放起作用,必须发生以下事情:
执行一些巧妙的操作
下面是我的XAML:
<s:ScatterView AllowDrop="True" Background="Transparent"
x:Name="scatterView" s:SurfaceDragDrop.Drop="scatterView_Drop">
<s:SurfaceButton Name="surfaceButton1">Button</s:SurfaceButton>
<s:LibraryStack>
<s:LibraryStackItem Content="Hello"></s:LibraryStackItem>
</s:LibraryStack>
</s:ScatterView>
</s:ScatterView>在代码中,我们处理Drop事件
private void scatterView_Drop(object sender, SurfaceDragDropEventArgs e)
{
Console.WriteLine("Got drop: " + e.Cursor.Data);
var newItem = new ScatterViewItem();
// Rely on .ToString() on the data. A real app would do something more clever
newItem.Content = e.Cursor.Data;
// Place the new item at the drop location
newItem.Center = e.Cursor.GetPosition(scatterView);
// Add it to the scatterview
scatterView.Items.Add(newItem);
}显然,上面的代码不能处理将项目拖回到库栏。我将其作为练习留给读者;-)
下面的MSDN指南我绝对认为你应该读一读:http://msdn.microsoft.com/en-us/library/ee804812.aspx
发布于 2010-03-16 04:57:09
你需要将scatterview上的背景画笔设置为一种颜色,即透明,即使是捕捉拖放事件也是如此。
您还需要使用SurfaceDragDrop。
新建ScatterManipulationStartedEventHandler(OnManipulationStarted));;SurfaceDragDrop.AddDropHandler(scatterView1,OnCursorDrop);SurfaceDragDrop.AddDropHandler(scatterView1,OnCursorDrop)
private void OnManipulationStarted(object sender, RoutedEventArgs args){ ScatterViewItem svi = args.OriginalSource as ScatterViewItem;if (svi != null)// && DragDropScatterView.GetAllowDrag(svi)) { svi.BeginDragDrop(svi.DataContext);}}
private void OnCursorDrop(object sender, SurfaceDragDropEventArgs args){ SurfaceDragCursor droppingCursor = args.Cursor;
// Add dropping Item that was from another drag source.
if (!scatterView1.Items.Contains(droppingCursor.Data)){
scatterView1.Items.Add(droppingCursor.Data);
var svi = scatterView1.ItemContainerGenerator.ContainerFromItem(droppingCursor.Data) as ScatterViewItem;
if (svi != null){
svi.Center = droppingCursor.GetPosition(scatterView1);
svi.Orientation = droppingCursor.GetOrientation(scatterView1);
svi.Height = droppingCursor.Visual.ActualHeight;
svi.Width = droppingCursor.Visual.ActualWidth;
svi.SetRelativeZIndex(RelativeScatterViewZIndex.Topmost);
}
}}
这基本上都是sdk中的一个例子,遗憾的是我不记得是哪一个了。
干杯,
斯蒂安·法斯塔德
https://stackoverflow.com/questions/1632909
复制相似问题