Click here to Skip to main content
15,886,798 members
Articles / Desktop Programming / WPF

WPF CRUD Generator (Scaffolding)

Rate me:
Please Sign up or sign in to vote.
4.89/5 (11 votes)
4 Jun 2009LGPL35 min read 88.2K   6.3K   61  
Semi-automatic GUI generation from Domain Models.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;

namespace Technewlogic.Crud.Controls
{
	[TemplatePart(Name = "PART_PropertyPanel", Type = typeof(Panel))]
	[StyleTypedProperty(Property = "DescriptionStyle", StyleTargetType = typeof(TextBlock))] // TODO
	public class PanelBase : TemplatedControl
	{
		private Panel _detailsGrid;

		static PanelBase()
		{
			DefaultStyleKeyProperty.OverrideMetadata(
				typeof(PanelBase),
				new FrameworkPropertyMetadata(typeof(PanelBase)));
		}

		public void AddField(string description, UIElement value)
		{
			// TODO: Styling (siehe StyleTypedPropertyAttribute oben)
			TextBlock tbDescription = new TextBlock()
			{
				Text = description + ":"
			};
			_detailsGrid.Children.Add(tbDescription);
			_detailsGrid.Children.Add(value);
		}

		public void ClearFields()
		{
			_detailsGrid.Children.Clear();
		}

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			AssignTemplateControl(ref _detailsGrid, new WrapPanel(), "PART_PropertyPanel");
		}
	}
}

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 GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) www.technewlogic.de
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions