Browse Source
And moved all item selecting logic etc in SelectingItemsControl where it should be.pull/10/head
15 changed files with 278 additions and 66 deletions
@ -0,0 +1,13 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="ISelectable.cs" company="Steven Kirk">
|
||||
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Controls |
||||
|
{ |
||||
|
public interface ISelectable |
||||
|
{ |
||||
|
bool IsSelected { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="ListBox.cs" company="Steven Kirk">
|
||||
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Controls |
||||
|
{ |
||||
|
using Perspex.Controls.Generators; |
||||
|
using Perspex.Controls.Primitives; |
||||
|
|
||||
|
public class ListBox : SelectingItemsControl |
||||
|
{ |
||||
|
protected override ItemContainerGenerator CreateItemContainerGenerator() |
||||
|
{ |
||||
|
return new TypedItemContainerGenerator<ListBoxItem>(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="ListBoxItem.cs" company="Steven Kirk">
|
||||
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Controls |
||||
|
{ |
||||
|
public class ListBoxItem : ContentControl, ISelectable |
||||
|
{ |
||||
|
public static readonly PerspexProperty<bool> IsSelectedProperty = |
||||
|
PerspexProperty.Register<ListBoxItem, bool>("IsSelected"); |
||||
|
|
||||
|
static ListBoxItem() |
||||
|
{ |
||||
|
PseudoClass(IsSelectedProperty, ":selected"); |
||||
|
} |
||||
|
|
||||
|
public bool IsSelected |
||||
|
{ |
||||
|
get { return this.GetValue(IsSelectedProperty); } |
||||
|
set { this.SetValue(IsSelectedProperty, value); } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="ListBoxItemStyle.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.Layout; |
||||
|
using Perspex.Media; |
||||
|
using Perspex.Controls.Shapes; |
||||
|
using Perspex.Styling; |
||||
|
using Perspex.Controls.Presenters; |
||||
|
using Perspex.Controls.Primitives; |
||||
|
|
||||
|
public class ListBoxItemStyle : Styles |
||||
|
{ |
||||
|
public ListBoxItemStyle() |
||||
|
{ |
||||
|
this.AddRange(new[] |
||||
|
{ |
||||
|
new Style(x => x.OfType<ListBoxItem>()) |
||||
|
{ |
||||
|
Setters = new[] |
||||
|
{ |
||||
|
new Setter(ListBoxItem.TemplateProperty, ControlTemplate.Create<ListBoxItem>(this.Template)), |
||||
|
}, |
||||
|
}, |
||||
|
new Style(x => x.OfType<ListBoxItem>().Class(":selected").Template().Id("border")) |
||||
|
{ |
||||
|
Setters = new[] |
||||
|
{ |
||||
|
new Setter(ListBoxItem.BackgroundProperty, new SolidColorBrush(0xff086f9e)), |
||||
|
new Setter(ListBoxItem.ForegroundProperty, Brushes.White), |
||||
|
}, |
||||
|
}, |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private Control Template(ListBoxItem control) |
||||
|
{ |
||||
|
return new Border |
||||
|
{ |
||||
|
Id = "border", |
||||
|
[~Border.BackgroundProperty] = control[~ListBoxItem.BackgroundProperty], |
||||
|
[~Border.BorderBrushProperty] = control[~ListBoxItem.BorderBrushProperty], |
||||
|
[~Border.BorderThicknessProperty] = control[~ListBoxItem.BorderThicknessProperty], |
||||
|
Content = new ContentPresenter |
||||
|
{ |
||||
|
[~ContentPresenter.ContentProperty] = control[~ListBoxItem.ContentProperty], |
||||
|
}, |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="ListBoxStyle.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.Controls.Presenters; |
||||
|
using Perspex.Media; |
||||
|
using Perspex.Styling; |
||||
|
|
||||
|
public class ListBoxStyle : Styles |
||||
|
{ |
||||
|
public ListBoxStyle() |
||||
|
{ |
||||
|
this.AddRange(new[] |
||||
|
{ |
||||
|
new Style(x => x.OfType<ListBox>()) |
||||
|
{ |
||||
|
Setters = new[] |
||||
|
{ |
||||
|
new Setter(ListBox.TemplateProperty, ControlTemplate.Create<ListBox>(this.Template)), |
||||
|
new Setter(ListBox.BorderBrushProperty, Brushes.Black), |
||||
|
new Setter(ListBox.BorderThicknessProperty, 1.0), |
||||
|
}, |
||||
|
}, |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private Control Template(ListBox control) |
||||
|
{ |
||||
|
return new Border |
||||
|
{ |
||||
|
Padding = new Thickness(4), |
||||
|
[~Border.BackgroundProperty] = control[~ListBox.BackgroundProperty], |
||||
|
[~Border.BorderBrushProperty] = control[~ListBox.BorderBrushProperty], |
||||
|
[~Border.BorderThicknessProperty] = control[~ListBox.BorderThicknessProperty], |
||||
|
Content = new ScrollViewer |
||||
|
{ |
||||
|
Content = new ItemsPresenter |
||||
|
{ |
||||
|
[~ItemsPresenter.ItemsProperty] = control[~ListBox.ItemsProperty], |
||||
|
[~ItemsPresenter.ItemsPanelProperty] = control[~ListBox.ItemsPanelProperty], |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue