8 changed files with 49 additions and 40 deletions
@ -0,0 +1,40 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,31 +0,0 @@ |
|||||
// -----------------------------------------------------------------------
|
|
||||
// <copyright file="TypedItemContainerGenerator.cs" company="Steven Kirk">
|
|
||||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|
||||
// </copyright>
|
|
||||
// -----------------------------------------------------------------------
|
|
||||
|
|
||||
namespace Perspex.Controls.Generators |
|
||||
{ |
|
||||
using Perspex.Controls.Templates; |
|
||||
|
|
||||
public class TypedItemContainerGenerator<T> : ItemContainerGenerator where T : ContentControl, new() |
|
||||
{ |
|
||||
public TypedItemContainerGenerator(Control owner) |
|
||||
: base(owner) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
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; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue