A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 lines
1.2 KiB

// -----------------------------------------------------------------------
// <copyright file="ControlTemplate.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
using System;
public class ControlTemplate
{
private Func<ITemplatedControl, Control> build;
public ControlTemplate(Func<ITemplatedControl, Control> build)
{
Contract.Requires<NullReferenceException>(build != null);
this.build = build;
}
public static ControlTemplate Create<TControl>(Func<TControl, Control> build)
where TControl : ITemplatedControl
{
Contract.Requires<NullReferenceException>(build != null);
return new ControlTemplate(c => build((TControl)c));
}
public Control Build(ITemplatedControl templatedParent)
{
Contract.Requires<NullReferenceException>(templatedParent != null);
Control root = this.build(templatedParent);
root.TemplatedParent = templatedParent;
return root;
}
}
}