Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 拖动网格内的矩形_Silverlight - Fatal编程技术网

Silverlight 拖动网格内的矩形

Silverlight 拖动网格内的矩形,silverlight,Silverlight,我设法解决了我的“可拖动网格内部”问题,但我发现了另一个问题 当我开始拖动矩形时,它会消失并重新出现在鼠标上 我的代码: public Page() { InitializeComponent(); dragGrid.AddHandler(RadDragAndDropManager.DragQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDragQuery)); dragGrid.AddHandle

我设法解决了我的“可拖动网格内部”问题,但我发现了另一个问题

当我开始拖动矩形时,它会消失并重新出现在鼠标上

我的代码:

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;
   }
  }
公共页面()
{
初始化组件();
AddHandler(RadDragAndDropManager.DragQueryEvent,新事件处理程序(OnDragQuery));
AddHandler(RadDragAndDropManager.DropQueryEvent,新事件处理程序(OnDropQuery));
AddHandler(RadDragAndDropManager.DropInfoEvent,新的EventHandler(OnDropInfo));
AddHandler(RadDragAndDropManager.DragInfoEvent,新事件处理程序(OnDragInfo));
已加载+=新的路由EventHandler(已加载页面);
}
已加载无效页面(对象发送器、路由目标)
{
//初始化可拖动的元素
SetAllowDrag(onePX,true);
SetAllowDrag(twoPX,true);
raddragandropmanager.SetAllowDrag(fourPX,true);
}
私有void OnDragQuery(对象发送方,DragDropQueryEventArgs e)
{
if(e.Options.Status==DragStatus.DragQuery)
{
e、 QueryResult=true;
//DragAndDropmanager将分离元素并在屏幕上拖动它。
var source=e.Options.source为矩形;
source.Visibility=Visibility.Collapsed;
e、 选项。有效载荷=源;
e、 已处理=正确;
}
if(e.Options.Status==DragStatus.DropSourceQuery)
{
e、 QueryResult=true;
}
}
私有void OnDropQuery(对象发送方,DragDropQueryEventArgs e)
{
if(e.Options.Status==DragStatus.DropDestinationQuery)
{
e、 QueryResult=true;
}
}
私有void OnDragInfo(对象发送方,DragDropRopevenTargs e)
{
if(e.Options.Status==DragStatus.DragCancel)
{
e、 Options.Source.Visibility=可见性.Visibility;
}
}
私有void OnDropInfo(对象发送器,DragDropEventArgs e)
{
if(e.Options.Status==DragStatus.DropComplete)
{
SetColumn(e.Options.Source,Grid.GetColumn(e.Options.Destination));
SetRow(e.Options.Source,Grid.GetRow(e.Options.Destination));
e、 Options.Source.Visibility=可见性.Visibility;
e、 已处理=正确;
}
}
XAML:



现在,我知道我的代码正在将矩形从网格中分离出来(这就是为什么它会消失的原因),任何我能阻止这种情况的想法(或者一个优雅的解决方案都很好)^ ^ ^

你的拖动并没有设置拖动提示。最简单的解决方案是在OnDRAGQUEST中间添加此代码。然后,您将在光标上拖动一个漂亮的匹配矩形:

        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;
我打开了网格,以便在拖动2x2矩形时可以清楚地看到此屏幕截图中的效果:


更新了我的问题,加入了XAML。这是一个很好的解决方案。但是,通常会使用装饰物来完成。@Avatar:请更详细地解释装饰物的使用。我们都在这里学习新事物,同时也提供帮助:)
        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;