1

我正在创建一个可视化设计器,为此我需要捕捉网格功能,如嘲笑Bird(Demo)提供的功能。有没有任何项目,用户控件或资源可以帮助我尽可能快地在silverlight中开发相同的项目。Silverlight对齐网格

我已经能够完成从工具箱(Listbox)到设计器屏幕中心的画布的拖放操作。但是对设计师来说,捕捉网格和网格功能非常棒。

回答

0

在您的MouseMove例程中,您需要执行额外的调整以允许捕捉。

void MainImage_MouseMove(object sender, MouseMoveEventArgs args){ 

    // ... assume you have calculated newX and newY already 

    adjustSnap(ref newX, ref newY); 

    // ... position your element 

} 

bool _isSnapOn = true; 

void adjustSnap(ref double x, ref double y) 
{ 
    const double gridWidth = 100; 
    const double gridHeight = 100; 

    if (_isSnapOn) 
    { 

     if (x % gridWidth < gridWidth/2) 
      x -= x % gridWidth; 
     else 
      x += (gridWidth - x % gridWidth); 

     if (y % gridHeight < gridHeight/2) 
      y -= y % gridHeight; 
     else 
      y += (gridHeight - y % gridHeight); 
    } 
} 
+0

逻辑似乎值得尝试,现在将它放在工作,并得到回 – Deeptechtons 2012-08-14 09:47:45