Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / WPF

DesignSurface - WPF Designer Extension

Rate me:
Please Sign up or sign in to vote.
4.80/5 (4 votes)
13 Oct 2011CPOL7 min read 44.5K   3K   27  
Helps you extend WPF designer and design controls right on the designer

#region NameSpace Improts

using System;
using Microsoft.Windows.Design.Interaction;
using System.Windows.Media;
using Microsoft.Windows.Design.Model;
using System.Windows.Controls;

#endregion

namespace Creatives.Design.Surface
{
	/// <summary>
	/// Defines a <see cref="SurfacePanel"/>.
	/// </summary>
	internal class SurfacePanel : AdornerPanel
	{
		#region Ctor

		public SurfacePanel(ModelItem modelItem, DesignerVerbCollection verbs)
			: base()
		{
			_verbs = verbs;
			_modelItem = modelItem;

			IsContentFocusable = true;
		}

		#endregion

		#region Properties

		private ModelItem _modelItem;
		private DesignerVerbCollection _verbs;
		private PropertyGrid _propertyGrid = null;

		public ModelItem ModelItem
		{
			get { return _modelItem; }
		}

		public DesignerVerbCollection Verbs
		{
			get { return _verbs; }
		}

		internal PropertyGrid PropertyGrid
		{
			get 
			{
				if (_propertyGrid == null)
				{
					_propertyGrid = new PropertyGrid(ModelItem, Verbs);
					
					InitPropertyGrid();
				}

				return _propertyGrid;
			}
		}

		#endregion

		#region Implementation

		private void InitPropertyGrid()
		{
			this.Children.Add(_propertyGrid);

			/* Positions the property grid to the right by 5 pixels */
			AdornerPanel.SetAdornerHorizontalAlignment(PropertyGrid, AdornerHorizontalAlignment.OutsideRight);
			AdornerPanel.SetAdornerVerticalAlignment(PropertyGrid, AdornerVerticalAlignment.Top);
			AdornerPanel.SetAdornerMargin(PropertyGrid, new System.Windows.Thickness(0, 0, 5, 5));
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
I code, learn, read and listen.

Comments and Discussions