csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
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.
48 lines
1.3 KiB
48 lines
1.3 KiB
namespace Perspex.Controls
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Perspex.Media;
|
|
|
|
public abstract class TemplatedControl : Control
|
|
{
|
|
public static readonly PerspexProperty<Func<TemplatedControl, Visual>> TemplateProperty =
|
|
PerspexProperty.Register<TemplatedControl, Func<TemplatedControl, Visual>>("Template");
|
|
|
|
private Visual visualChild;
|
|
|
|
public TemplatedControl()
|
|
{
|
|
this.Template = owner => this.DefaultTemplate();
|
|
}
|
|
|
|
public Func<TemplatedControl, Visual> Template
|
|
{
|
|
get { return this.GetValue(TemplateProperty); }
|
|
set { this.SetValue(TemplateProperty, value); }
|
|
}
|
|
|
|
public override IEnumerable<Visual> VisualChildren
|
|
{
|
|
get
|
|
{
|
|
var template = this.Template;
|
|
|
|
if (this.visualChild == null && template != null)
|
|
{
|
|
this.visualChild = template(this);
|
|
this.visualChild.VisualParent = this;
|
|
}
|
|
|
|
return Enumerable.Repeat(this.visualChild, this.visualChild != null ? 1 : 0);
|
|
}
|
|
}
|
|
|
|
public sealed override void Render(IDrawingContext context)
|
|
{
|
|
}
|
|
|
|
protected abstract Visual DefaultTemplate();
|
|
}
|
|
}
|
|
|