Click here to Skip to main content
15,893,594 members
Articles / Desktop Programming / WPF

ListView Layout Manager

Rate me:
Please Sign up or sign in to vote.
4.92/5 (68 votes)
27 Sep 2012CPOL4 min read 594.9K   9.1K   265  
WPF: Customizing ListView/GridView Column-Layout
// -- FILE ------------------------------------------------------------------
// name       : ProportionalColumn.cs
// created    : Jani Giannoudis - 2008.03.27
// language   : c#
// environment: .NET 3.0
// copyright  : (c) 2008-2012 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System.Windows;
using System.Windows.Controls;

namespace Itenso.Windows.Controls.ListViewLayout
{

	// ------------------------------------------------------------------------
	public sealed class ProportionalColumn : LayoutColumn
	{

		// ----------------------------------------------------------------------
		public static readonly DependencyProperty WidthProperty = 
			DependencyProperty.RegisterAttached(
				"Width",
				typeof( double ),
				typeof( ProportionalColumn ) );

		// ----------------------------------------------------------------------
		private ProportionalColumn()
		{
		} // ProportionalColumn

		// ----------------------------------------------------------------------
		public static double GetWidth( DependencyObject obj )
		{
			return (double)obj.GetValue( WidthProperty );
		} // GetWidth

		// ----------------------------------------------------------------------
		public static void SetWidth( DependencyObject obj, double width )
		{
			obj.SetValue( WidthProperty, width );
		} // SetWidth

		// ----------------------------------------------------------------------
		public static bool IsProportionalColumn( GridViewColumn column )
		{
			if ( column == null )
			{
				return false;
			}
			return HasPropertyValue( column, WidthProperty );
		} // IsProportionalColumn

		// ----------------------------------------------------------------------
		public static double? GetProportionalWidth( GridViewColumn column )
		{
			return GetColumnWidth( column, WidthProperty );
		} // GetProportionalWidth

		// ----------------------------------------------------------------------
		public static GridViewColumn ApplyWidth( GridViewColumn gridViewColumn, double width )
		{
			SetWidth( gridViewColumn, width );
			return gridViewColumn;
		} // ApplyWidth

	} // class ProportionalColumn

} // namespace Itenso.Windows.Controls.ListViewLayout
// -- EOF -------------------------------------------------------------------

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
Software Developer (Senior)
Switzerland Switzerland
👨 Senior .NET Software Engineer

🚀 My Open Source Projects
- Time Period Library 👉 GitHub
- Payroll Engine 👉 GitHub

Feedback and contributions are welcome.



Comments and Discussions