9 changed files with 185 additions and 18 deletions
@ -0,0 +1,42 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="DataTemplate.cs" company="Steven Kirk">
|
||||
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Controls |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Reflection; |
||||
|
|
||||
|
public class DataTemplate |
||||
|
{ |
||||
|
public DataTemplate(Type type, Func<object, IVisual> build) |
||||
|
: this(o => type.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo()), build) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public DataTemplate(Func<object, bool> match, Func<object, IVisual> build) |
||||
|
{ |
||||
|
this.Match = match; |
||||
|
this.Build = build; |
||||
|
} |
||||
|
|
||||
|
public Func<object, bool> Match { get; private set; } |
||||
|
|
||||
|
public Func<object, IVisual> Build { get; private set; } |
||||
|
} |
||||
|
|
||||
|
public class DataTemplate<T> : DataTemplate |
||||
|
{ |
||||
|
public DataTemplate(Func<T, IVisual> build) |
||||
|
: base(typeof(T), o => build((T)o)) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public DataTemplate(Func<T, bool> match, Func<T, IVisual> build) |
||||
|
: base(o => (o is T) ? match((T)o) : false, o => build((T)o)) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="DataTemplates.cs" company="Steven Kirk">
|
||||
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Controls |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Collections.Specialized; |
||||
|
using System.Linq; |
||||
|
using System.Reactive; |
||||
|
using System.Reactive.Subjects; |
||||
|
|
||||
|
public class DataTemplates : PerspexList<DataTemplate> |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="ContentControlStyle.cs" company="Steven Kirk">
|
||||
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Themes.Default |
||||
|
{ |
||||
|
using System.Linq; |
||||
|
using Perspex.Controls; |
||||
|
using Perspex.Media; |
||||
|
using Perspex.Styling; |
||||
|
|
||||
|
public class ContentControlStyle : Styles |
||||
|
{ |
||||
|
public ContentControlStyle() |
||||
|
{ |
||||
|
this.AddRange(new[] |
||||
|
{ |
||||
|
new Style(x => x.OfType<ContentControl>()) |
||||
|
{ |
||||
|
Setters = new[] |
||||
|
{ |
||||
|
new Setter(Button.TemplateProperty, ControlTemplate.Create<ContentControl>(this.Template)), |
||||
|
}, |
||||
|
}, |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private Control Template(ContentControl control) |
||||
|
{ |
||||
|
return new ContentPresenter |
||||
|
{ |
||||
|
[~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty], |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue