예제 #1
0
 public void Edit()
 {
     _layoutPreview = null;
     if (DataContext is GridLayoutModel)
     {
         _editor = new GridEditor();
     }
     else if (DataContext is CanvasLayoutModel)
     {
         _editor = new CanvasEditor();
     }
     Content = _editor;
 }
예제 #2
0
        public Int32Rect[] GetZoneRects()
        {
            // TODO: the ideal here is that the ArrangeRects logic is entirely inside the model, so we don't have to walk the UIElement children to get the rect info
            Panel previewPanel = null;

            if (_editor != null)
            {
                GridEditor gridEditor = _editor as GridEditor;
                if (gridEditor != null)
                {
                    previewPanel = gridEditor.PreviewPanel;
                }
                else
                {
                    //CanvasEditor
                    previewPanel = ((CanvasEditor)_editor).Preview;
                }
            }
            else
            {
                previewPanel = _layoutPreview.PreviewPanel;
            }

            var count = previewPanel.Children.Count;

            Int32Rect[] zones = new Int32Rect[count];

            int i = 0;

            foreach (FrameworkElement child in previewPanel.Children)
            {
                Point topLeft = child.TransformToAncestor(previewPanel).Transform(new Point());

                var right  = topLeft.X + child.ActualWidth;
                var bottom = topLeft.Y + child.ActualHeight;
                zones[i].X      = (int)topLeft.X;
                zones[i].Y      = (int)topLeft.Y;
                zones[i].Width  = (int)child.ActualWidth;
                zones[i].Height = (int)child.ActualHeight;
                i++;
            }

            return(zones);
        }