2010-08-24 55 views
1

我设法排序我的“可拖动内网格”问题,但是我发现了另一个问题。拖动一个网格内的矩形

当我开始拖动矩形时,消失并重新出现在mouseup上。

我的代码:

public Page() 
    { 
    InitializeComponent(); 

    dragGrid.AddHandler(RadDragAndDropManager.DragQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDragQuery)); 
    dragGrid.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDropQuery)); 
    dragGrid.AddHandler(RadDragAndDropManager.DropInfoEvent, new EventHandler<DragDropEventArgs>(OnDropInfo)); 
    dragGrid.AddHandler(RadDragAndDropManager.DragInfoEvent, new EventHandler<DragDropEventArgs>(OnDragInfo)); 

    Loaded += new RoutedEventHandler(Page_Loaded); 
    } 

    void Page_Loaded(object sender, RoutedEventArgs e) 
    { 
    //Initialise the draggable elements 
    RadDragAndDropManager.SetAllowDrag(onePX, true); 
    RadDragAndDropManager.SetAllowDrag(twoPX, true); 
    RadDragAndDropManager.SetAllowDrag(fourPX, true); 
    } 

    private void OnDragQuery(object sender, DragDropQueryEventArgs e) 
    { 
    if (e.Options.Status == DragStatus.DragQuery) 
    { 
    e.QueryResult = true; 

    //The DragAndDropmanager will detach the element and drag it around the screen. 
    var source = e.Options.Source as Rectangle; 
    source.Visibility = Visibility.Collapsed; 

    e.Options.Payload = source; 

    e.Handled = true; 
    } 

    if (e.Options.Status == DragStatus.DropSourceQuery) 
    { 
    e.QueryResult = true; 
    } 
    } 

    private void OnDropQuery(object sender, DragDropQueryEventArgs e) 
    { 
    if (e.Options.Status == DragStatus.DropDestinationQuery) 
    { 
    e.QueryResult = true; 
    } 
    } 

    private void OnDragInfo(object sender, DragDropEventArgs e) 
    { 
    if (e.Options.Status == DragStatus.DragCancel) 
    { 
    e.Options.Source.Visibility = Visibility.Visible; 
    } 
    } 

    private void OnDropInfo(object sender, DragDropEventArgs e) 
    { 
    if (e.Options.Status == DragStatus.DropComplete) 
    { 
    Grid.SetColumn(e.Options.Source, Grid.GetColumn(e.Options.Destination)); 
    Grid.SetRow(e.Options.Source, Grid.GetRow(e.Options.Destination)); 

    e.Options.Source.Visibility = Visibility.Visible; 

    e.Handled = true; 
    } 
    } 

XAML:

<UserControl 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:dragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="TestBench.Page" 
     MinHeight="500" MinWidth="300"> 
    <Grid x:Name="LayoutRoot" Background="White"> 
    <Grid x:Name="dragGrid" Margin="0,0,0,58" ShowGridLines="False"> 
     <Grid.RowDefinitions> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     <RowDefinition Height="32" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     <ColumnDefinition Width="32" /> 
     </Grid.ColumnDefinitions> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="0" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="0" /> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="1" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="1" /> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="2" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="2" /> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="3" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="3" /> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="4" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="4" /> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="5" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="5" /> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="6" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="6" /> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="7" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="7" /> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="8" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="8" /> 

     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="0" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="1" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="2" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="3" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="4" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="5" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="6" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="7" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="8" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="9" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="10" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="11" Grid.Row="9" /> 
     <Rectangle dragDrop:RadDragAndDropManager.AllowDrop="True" Fill="LightBlue" 
     Grid.Column="12" Grid.Row="9" /> 

     <Rectangle Width="32" Height="32" Fill="Black" x:Name="onePX" 
     Grid.Column="0" Grid.Row="0" /> 

     <Rectangle Width="32" Height="64" Fill="Black" x:Name="twoPX" 
     Grid.Column="0" Grid.Row="2" Grid.RowSpan="2" /> 

     <Rectangle Width="64" Height="64" Fill="Black" x:Name="fourPX" 
     Grid.Column="0" Grid.Row="5" 
     Grid.ColumnSpan="2" 
     Grid.RowSpan="2" /> 
     <TextBlock x:Name="textOutput" HorizontalAlignment="Left" Margin="8,8,0,8" Grid.Row="10" Grid.RowSpan="2" TextWrapping="Wrap" Text="TextBlock" d:LayoutOverrides="Height" Grid.ColumnSpan="6" Width="184"/> 
    </Grid> 
    </Grid> 
</UserControl> 

现在,我知道我的代码分离从电网矩形(这就是为什么它是dissapearing),任何想法如何我可以阻止这个(或者一个优雅的工作会很好)^ _^

+0

更新我的问题,包括XAML – 2010-08-24 13:16:57

回答

2

您的拖动不会设置拖动提示。 SImplest的解决方法是在OnDragQuery中添加此代码。那么你会得到一个很好的匹配矩形拖动鼠标光标:

 source.Visibility = Visibility.Collapsed; 
     /* add these 5 lines - copies properties into a drag cue */ 
     var cue = new Rectangle(); 
     cue.Height = source.Height; 
     cue.Width = source.Width; 
     cue.Fill = source.Fill; 
     e.Options.DragCue = cue; 

     e.Options.Payload = source; 

我打开了网格,以便你可以在此屏幕截图清楚地看到效果为2×2矩形拖:

alt text

+0

这是一个很好的解决方案。但是,通常使用Adorners来完成。 – 2010-08-24 18:30:47

+0

@Avatar:请详细解释Adorners的用法。我们都在这里学习新事物以及帮助:) – 2010-08-24 20:02:39

+0

出色的工作我的朋友!感谢您! + 1rep – 2010-08-25 08:18:31