Browse Source

Merge branch 'master' into devtools

pull/403/head
Steven Kirk 10 years ago
parent
commit
17daf832f1
  1. 30
      src/Perspex.Base/PerspexObjectExtensions.cs
  2. 30
      src/Perspex.Controls/ControlExtensions.cs
  3. 23
      src/Perspex.Controls/TreeView.cs
  4. 13
      src/Perspex.Styling/Styling/Setter.cs
  5. 25
      tests/Perspex.Controls.UnitTests/TreeViewTests.cs

30
src/Perspex.Base/PerspexObjectExtensions.cs

@ -164,6 +164,36 @@ namespace Perspex
return result;
}
/// <summary>
/// Binds a property on an <see cref="IPerspexObject"/> to an <see cref="IBinding"/>.
/// </summary>
/// <param name="o">The object.</param>
/// <param name="property">The property to bind.</param>
/// <param name="binding">The binding.</param>
/// <returns>An <see cref="IDisposable"/> which can be used to cancel the binding.</returns>
public static IDisposable Bind(
this IPerspexObject o,
PerspexProperty property,
IBinding binding)
{
Contract.Requires<ArgumentNullException>(o != null);
Contract.Requires<ArgumentNullException>(property != null);
Contract.Requires<ArgumentNullException>(binding != null);
var mode = binding.Mode;
if (mode == BindingMode.Default)
{
mode = property.DefaultBindingMode;
}
return o.Bind(
property,
binding.CreateSubject(o, property),
mode,
binding.Priority);
}
/// <summary>
/// Binds a property to a subject according to a <see cref="BindingMode"/>.
/// </summary>

30
src/Perspex.Controls/ControlExtensions.cs

@ -14,36 +14,6 @@ namespace Perspex.Controls
/// </summary>
public static class ControlExtensions
{
/// <summary>
/// Binds a property on an <see cref="IControl"/> to an <see cref="IBinding"/>.
/// </summary>
/// <param name="o">The object.</param>
/// <param name="property">The property to bind.</param>
/// <param name="binding">The binding.</param>
/// <returns>An <see cref="IDisposable"/> which can be used to cancel the binding.</returns>
public static IDisposable Bind(
this IControl o,
PerspexProperty property,
IBinding binding)
{
Contract.Requires<ArgumentNullException>(o != null);
Contract.Requires<ArgumentNullException>(property != null);
Contract.Requires<ArgumentNullException>(binding != null);
var mode = binding.Mode;
if (mode == BindingMode.Default)
{
mode = property.DefaultBindingMode;
}
return o.Bind(
property,
binding.CreateSubject(o, property),
mode,
binding.Priority);
}
/// <summary>
/// Tries to being the control into view.
/// </summary>

23
src/Perspex.Controls/TreeView.cs

@ -46,8 +46,27 @@ namespace Perspex.Controls
/// </summary>
public object SelectedItem
{
get { return _selectedItem; }
set { SetAndRaise(SelectedItemProperty, ref _selectedItem, value); }
get
{
return _selectedItem;
}
set
{
if (_selectedItem != null)
{
var container = ItemContainerGenerator.Index.ContainerFromItem(_selectedItem);
MarkContainerSelected(container, false);
}
SetAndRaise(SelectedItemProperty, ref _selectedItem, value);
if (_selectedItem != null)
{
var container = ItemContainerGenerator.Index.ContainerFromItem(_selectedItem);
MarkContainerSelected(container, true);
}
}
}
/// <inheritdoc/>

13
src/Perspex.Styling/Styling/Setter.cs

@ -79,7 +79,7 @@ namespace Perspex.Styling
{
if (activator == null)
{
Bind(control, Property, binding);
control.Bind(Property, binding);
}
else
{
@ -102,15 +102,10 @@ namespace Perspex.Styling
}
}
private void Bind(IStyleable control, PerspexProperty property, IBinding binding)
{
Bind(control, property, binding, binding.CreateSubject(control, property));
}
private void Bind(
IStyleable control,
PerspexProperty property,
IBinding binding,
IStyleable control,
PerspexProperty property,
IBinding binding,
ISubject<object> subject)
{
var mode = binding.Mode;

25
tests/Perspex.Controls.UnitTests/TreeViewTests.cs

@ -107,6 +107,31 @@ namespace Perspex.Controls.UnitTests
Assert.True(container.IsSelected);
}
[Fact]
public void Setting_SelectedItem_Should_Set_Container_Selected()
{
var tree = CreateTestTreeData();
var target = new TreeView
{
Template = CreateTreeViewTemplate(),
Items = tree,
DataTemplates = CreateNodeDataTemplate(),
};
var visualRoot = new TestRoot();
visualRoot.Child = target;
ApplyTemplates(target);
var item = tree[0].Children[1].Children[0];
var container = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(item);
Assert.NotNull(container);
target.SelectedItem = item;
Assert.True(container.IsSelected);
}
[Fact]
public void LogicalChildren_Should_Be_Set()
{

Loading…
Cancel
Save