Using LibraryStacks in a Surface ScatterView

We are trying to figure out how to drag an item from the LibraryStack container to ScatterView, for example, how sample applications for viewing photos work. Currently, the item simply returns back to LibraryStack after we pulled it out. We can drag and drop items into other libraries or LibraryBars libraries.

Here is an example of what we are trying:

<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>

Thanks!

+3
source share
2 answers

, , . , , , , .

, , , /, :

  • AllowDrop true
  • ( , , - Transparent)
  • drop Drop -

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

+3

, .. , .

SurfaceDragDrop.

SurfaceDragDrop.AddDropHandler(scatterView1, OnCursorDrop); AddHandler (ScatterViewItem.ScatterManipulationStartedEvent, ScatterManipulationStartedEventHandler (OnManipulationStarted));

private void OnManipulationStarted(object sender, RoutedEventArgs args)

{   ScatterViewItem svi = args.OriginalSource 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, , .

,

+1

Source: https://habr.com/ru/post/1721219/


All Articles