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.
 
 
 

40 lines
1.3 KiB

// -----------------------------------------------------------------------
// <copyright file="ItemContainerGenerator`1.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls.Generators
{
using Perspex.Controls.Templates;
/// <summary>
/// Creates containers for items and maintains a list of created containers.
/// </summary>
/// <typeparam name="T">The type of the container.</typeparam>
public class ItemContainerGenerator<T> : ItemContainerGenerator where T : class, IContentControl, new()
{
/// <summary>
/// Initializes a new instance of the <see cref="ItemContainerGenerator{T}"/> class.
/// </summary>
/// <param name="owner">The owner control.</param>
public ItemContainerGenerator(Control owner)
: base(owner)
{
}
/// <inheritdoc/>
protected override IControl CreateContainer(object item, IDataTemplate itemTemplate)
{
T result = item as T;
if (result == null)
{
result = new T();
result.Content = this.Owner.MaterializeDataTemplate(item);
}
return result;
}
}
}