10 changed files with 220 additions and 29 deletions
@ -0,0 +1,44 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Deck.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Controls |
|||
{ |
|||
using System.Collections; |
|||
using Perspex.Controls.Generators; |
|||
using Perspex.Controls.Primitives; |
|||
using Perspex.Controls.Utils; |
|||
|
|||
/// <summary>
|
|||
/// A selecting items control that displays a single item that fills the control.
|
|||
/// </summary>
|
|||
public class Deck : SelectingItemsControl |
|||
{ |
|||
private static readonly ItemsPanelTemplate PanelTemplate = |
|||
new ItemsPanelTemplate(() => new Panel()); |
|||
|
|||
static Deck() |
|||
{ |
|||
ItemsPanelProperty.OverrideDefaultValue(typeof(Deck), PanelTemplate); |
|||
} |
|||
|
|||
protected override ItemContainerGenerator CreateItemContainerGenerator() |
|||
{ |
|||
return new TypedItemContainerGenerator<DeckItem>(this); |
|||
} |
|||
|
|||
protected override void ItemsChanged(IEnumerable oldValue, IEnumerable newValue) |
|||
{ |
|||
base.ItemsChanged(oldValue, newValue); |
|||
|
|||
var items = this.Items; |
|||
|
|||
if (items != null && items.Count() > 0) |
|||
{ |
|||
this.SelectedIndex = 0; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="DeckItem.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Controls |
|||
{ |
|||
public class DeckItem : ContentControl, ISelectable |
|||
{ |
|||
public static readonly PerspexProperty<bool> IsSelectedProperty = |
|||
PerspexProperty.Register<DeckItem, bool>("IsSelected"); |
|||
|
|||
static DeckItem() |
|||
{ |
|||
Control.PseudoClass(IsSelectedProperty, ":selected"); |
|||
} |
|||
|
|||
public bool IsSelected |
|||
{ |
|||
get { return this.GetValue(IsSelectedProperty); } |
|||
set { this.SetValue(IsSelectedProperty, value); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="DeckItemStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using Perspex.Controls; |
|||
using Perspex.Controls.Presenters; |
|||
using Perspex.Styling; |
|||
using System.Linq; |
|||
|
|||
public class DeckItemStyle : Styles |
|||
{ |
|||
public DeckItemStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<DeckItem>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(DeckItem.TemplateProperty, ControlTemplate.Create<DeckItem>(this.Template)), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(DeckItem control) |
|||
{ |
|||
return new ContentPresenter |
|||
{ |
|||
[~ContentPresenter.ContentProperty] = control[~DeckItem.ContentProperty], |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="DeckStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using Perspex.Controls; |
|||
using Perspex.Controls.Presenters; |
|||
using Perspex.Styling; |
|||
using System.Linq; |
|||
|
|||
public class DeckStyle : Styles |
|||
{ |
|||
public DeckStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<Deck>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Deck.TemplateProperty, ControlTemplate.Create<Deck>(this.Template)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<Deck>().Descendent().Is<DeckItem>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Control.IsVisibleProperty, false), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<Deck>().Descendent().Is<DeckItem>().Class(":selected")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Control.IsVisibleProperty, true), |
|||
}, |
|||
} |
|||
}); |
|||
} |
|||
|
|||
private Control Template(Deck control) |
|||
{ |
|||
return new ItemsPresenter |
|||
{ |
|||
Id = "itemsPresenter", |
|||
[~ItemsPresenter.ItemsProperty] = control[~Deck.ItemsProperty], |
|||
[~ItemsPresenter.ItemsPanelProperty] = control[~Deck.ItemsPanelProperty], |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue