首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ScatterView on Surface中使用LibraryStacks

在ScatterView on Surface中使用LibraryStacks
EN

Stack Overflow用户
提问于 2009-10-28 02:52:43
回答 2查看 3.3K关注 0票数 3

我们正在尝试弄清楚如何将项目从LibraryStack容器拖到ScatterView上,就像照片查看器示例应用程序的工作方式一样。目前,项目只是在我们将其拖出后飞回LibraryStack。我们可以将项目拖放到其他LibraryStacks或LibraryBars中。

以下是我们正在尝试的示例:

代码语言:javascript
复制
<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>

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-03-17 18:22:12

这当然是可行的。我编写了一个示例,允许您从散点视图中的库栏中拖动项目,并将项目拖放到散点视图中,这些项目将显示为新的散点视图。

我不确定你哪里出错了,但是为了让拖放起作用,必须发生以下事情:

  1. drop目标必须将AllowDrop设置为true
  2. drop目标必须对命中测试可见(通常通过设置非null的背景来完成-I use Transparent)
  3. The drop target必须处理Drop事件并使用data

执行一些巧妙的操作

下面是我的XAML:

代码语言:javascript
复制
<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事件

代码语言:javascript
复制
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

票数 3
EN

Stack Overflow用户

发布于 2010-03-16 04:57:09

你需要将scatterview上的背景画笔设置为一种颜色,即透明,即使是捕捉拖放事件也是如此。

您还需要使用SurfaceDragDrop。

新建ScatterManipulationStartedEventHandler(OnManipulationStarted));;SurfaceDragDrop.AddDropHandler(scatterView1,OnCursorDrop);SurfaceDragDrop.AddDropHandler(scatterView1,OnCursorDrop)

代码语言:javascript
复制
private void OnManipulationStarted(object sender, RoutedEventArgs args)

{ ScatterViewItem svi = args.OriginalSource as ScatterViewItem;if (svi != null)// && DragDropScatterView.GetAllowDrag(svi)) { svi.BeginDragDrop(svi.DataContext);}}

代码语言:javascript
复制
private void OnCursorDrop(object sender, SurfaceDragDropEventArgs args)

{ SurfaceDragCursor droppingCursor = args.Cursor;

代码语言:javascript
复制
// 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中的一个例子,遗憾的是我不记得是哪一个了。

干杯,

斯蒂安·法斯塔德

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1632909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档