문제

사진 뷰어 샘플 응용 프로그램이 작동하는 방식과 같은 라이브러리 스택 컨테이너에서 항목을 산란 뷰로 드래그하는 방법을 알아 내려고 노력하고 있습니다. 현재 항목은 드래그 후 라이브러리 스택으로 다시 날아갑니다. 다른 도서관 스택이나 도서관 바로 항목을 드래그 앤 드래그 할 수 있습니다.

다음은 우리가 시도하는 것의 샘플입니다.

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

감사!

도움이 되었습니까?

해결책

이것은 확실히 가능합니다. 나는 당신이 scatterview 내에있는 라이브러리 바에서 아이템을 드래그 할 수있는 예를 들고 새 scatterviewitems로 나타나는 Scatterview의 항목을 드롭 할 수 있습니다.

당신이 어디에서 잘못되었는지 잘 모르겠지만 드래그/드롭이 작동하기 위해서는 다음과 같습니다.

  1. 드롭 대상은 허용 드롭이 true로 설정되어 있어야합니다
  2. 드롭 대상은 적중 테스트를 위해 볼 수 있어야합니다 (일반적으로 NULL 이외의 배경을 설정하여 수행 - 투명한 사용).
  3. 드롭 대상은 드롭 이벤트를 처리하고 데이터로 영리한 일을해야합니다.

여기 내 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>

그리고 코드에서, 우리는 드롭 이벤트를 처리합니다

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

다른 팁

Scatterview의 배경 브러시를 색상으로 설정해야합니다. 즉, 드롭 이벤트를 잡기 위해 투명합니다.

SurfacedRagdrop도 사용해야합니다.

SurfacedRagdrop.adddrophandler (ScatterView1, OncursOrdrop); addHandler (scatterViewItem.ScatterManipulationStartEdevent, New 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의 예에서 나온 것입니다. 나는 그 중 어느 것이 슬프게도 그들 중 하나를 기억하지 않습니다.

건배,

Stian Farstad

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top