Monday 10 January 2011

Extended ListView WPF Custom Control (Part 1)

I am trying to write a WPF control that can be used in my projects to provide a standardised look and feel for data that is presented via grids. I'll put my thoughts down here, as a aid to my fading memory.

First I'll create the control, descended from ContentControl (as it will contain further content)

namespace Controls
{
using System;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using System.ComponentModel;

public class ListViewExtended : ContentControl
{
static ListViewExtended()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ListViewExtended),
new FrameworkPropertyMetadata(typeof(ListViewExtended)));
}
}
}


This is really simple, and is a standard setup, next the difficult bit is creating the correct XAML template, this looks (in the initial version anyway), like this:





This can be used as follows:















I'll tidy this up and add a screenshot later, and then extend the example to show it doing what I want it actually to do in the next post