20 changed files with 499 additions and 120 deletions
@ -0,0 +1,25 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="HeaderedItemsControl.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.Linq; |
|||
using System.Reactive.Linq; |
|||
|
|||
public class HeaderedItemsControl : ItemsControl |
|||
{ |
|||
public static readonly PerspexProperty<object> HeaderProperty = |
|||
HeaderedContentControl.HeaderProperty.AddOwner<HeaderedItemsControl>(); |
|||
|
|||
public object Header |
|||
{ |
|||
get { return this.GetValue(HeaderProperty); } |
|||
set { this.SetValue(HeaderProperty, value); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TreeDataTemplate.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Controls |
|||
{ |
|||
using System; |
|||
using System.Collections; |
|||
|
|||
public class TreeDataTemplate : DataTemplate |
|||
{ |
|||
public TreeDataTemplate( |
|||
Func<object, Control> build, |
|||
Func<object, IEnumerable> itemsSelector) |
|||
: this(o => true, build, itemsSelector) |
|||
{ |
|||
} |
|||
|
|||
public TreeDataTemplate( |
|||
Type type, |
|||
Func<object, Control> build, |
|||
Func<object, IEnumerable> itemsSelector) |
|||
: this(o => IsInstance(o, type), build, itemsSelector) |
|||
{ |
|||
} |
|||
|
|||
public TreeDataTemplate( |
|||
Func<object, bool> match, |
|||
Func<object, Control> build, |
|||
Func<object, IEnumerable> itemsSelector) |
|||
: base(match, build) |
|||
{ |
|||
this.ItemsSelector = itemsSelector; |
|||
} |
|||
|
|||
public Func<object, IEnumerable> ItemsSelector { get; private set; } |
|||
} |
|||
|
|||
public class TreeDataTemplate<T> : TreeDataTemplate |
|||
{ |
|||
public TreeDataTemplate( |
|||
Func<object, Control> build, |
|||
Func<T, IEnumerable> itemsSelector) |
|||
: base(typeof(T), o => build((T)o), o => itemsSelector((T)o)) |
|||
{ |
|||
} |
|||
|
|||
public TreeDataTemplate( |
|||
Func<T, bool> match, |
|||
Func<T, Control> build, |
|||
Func<T, IEnumerable> itemsSelector) |
|||
: base(o => (o is T) ? match((T)o) : false, o => build((T)o), o => itemsSelector((T)o)) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TreeView.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.Linq; |
|||
using System.Reactive.Linq; |
|||
|
|||
public class TreeView : SelectingItemsControl |
|||
{ |
|||
protected override Control CreateItemControlOverride(object item) |
|||
{ |
|||
TreeViewItem result = item as TreeViewItem; |
|||
|
|||
if (result == null) |
|||
{ |
|||
TreeDataTemplate template = this.GetTreeDataTemplate(item); |
|||
|
|||
result = new TreeViewItem |
|||
{ |
|||
Header = template.Build(item), |
|||
Items = template.ItemsSelector(item), |
|||
}; |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
private TreeDataTemplate GetTreeDataTemplate(object item) |
|||
{ |
|||
DataTemplate template = this.GetDataTemplate(item); |
|||
TreeDataTemplate treeTemplate = template as TreeDataTemplate; |
|||
|
|||
if (treeTemplate == null) |
|||
{ |
|||
treeTemplate = new TreeDataTemplate(template.Build, x => null); |
|||
} |
|||
|
|||
return treeTemplate; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TreeViewItem.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.Linq; |
|||
using System.Reactive.Linq; |
|||
|
|||
public class TreeViewItem : HeaderedItemsControl |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TreeViewItemStyle.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.Styling; |
|||
|
|||
public class TreeViewItemStyle : Styles |
|||
{ |
|||
public TreeViewItemStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<TreeViewItem>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.TemplateProperty, ControlTemplate.Create<TreeViewItem>(this.Template)), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(TreeViewItem control) |
|||
{ |
|||
return new StackPanel |
|||
{ |
|||
Children = new Controls |
|||
{ |
|||
new ContentPresenter |
|||
{ |
|||
[~ContentPresenter.ContentProperty] = control[~TreeViewItem.HeaderProperty], |
|||
}, |
|||
new ItemsPresenter |
|||
{ |
|||
Margin = new Thickness(13, 0, 0, 0), |
|||
[~ItemsPresenter.ItemsProperty] = control[~TreeViewItem.ItemsProperty], |
|||
[~ItemsPresenter.ItemsPanelProperty] = control[~TreeViewItem.ItemsPanelProperty], |
|||
} |
|||
} |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TreeViewStyle.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.Styling; |
|||
|
|||
public class TreeViewStyle : Styles |
|||
{ |
|||
public TreeViewStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<TreeView>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.TemplateProperty, ControlTemplate.Create<TreeView>(this.Template)), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(TreeView control) |
|||
{ |
|||
return new ItemsPresenter |
|||
{ |
|||
[~ItemsPresenter.ItemsProperty] = control[~TreeView.ItemsProperty], |
|||
[~ItemsPresenter.ItemsPanelProperty] = control[~TreeView.ItemsPanelProperty], |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue