Browse Source

Use string XamlBindingDefinition.SourcePropertyPath.

pull/237/head
Steven Kirk 11 years ago
parent
commit
3cb479769d
  1. 3
      src/Markup/Perspex.Markup.Xaml/DataBinding/PerspexPropertyBinder.cs
  2. 28
      src/Markup/Perspex.Markup.Xaml/DataBinding/XamlBindingDefinition.cs
  3. 8
      src/Markup/Perspex.Markup.Xaml/MarkupExtensions/BindingExtension.cs
  4. 6
      tests/Perspex.Markup.Xaml.UnitTests/BindingDefinitionBuilder.cs

3
src/Markup/Perspex.Markup.Xaml/DataBinding/PerspexPropertyBinder.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OmniXaml.TypeConversion; using OmniXaml.TypeConversion;
using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
namespace Perspex.Markup.Xaml.DataBinding namespace Perspex.Markup.Xaml.DataBinding
{ {
@ -47,7 +48,7 @@ namespace Perspex.Markup.Xaml.DataBinding
var binding = new XamlBinding(_typeConverterProvider) var binding = new XamlBinding(_typeConverterProvider)
{ {
BindingMode = xamlBinding.BindingMode, BindingMode = xamlBinding.BindingMode,
SourcePropertyPath = xamlBinding.SourcePropertyPath, SourcePropertyPath = new PropertyPath(xamlBinding.SourcePropertyPath),
Target = xamlBinding.Target, Target = xamlBinding.Target,
TargetProperty = xamlBinding.TargetProperty TargetProperty = xamlBinding.TargetProperty
}; };

28
src/Markup/Perspex.Markup.Xaml/DataBinding/XamlBindingDefinition.cs

@ -2,31 +2,29 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using Perspex.Controls; using Perspex.Controls;
using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
namespace Perspex.Markup.Xaml.DataBinding namespace Perspex.Markup.Xaml.DataBinding
{ {
public class XamlBindingDefinition public class XamlBindingDefinition
{ {
private readonly PropertyPath _sourcePropertyPath; public XamlBindingDefinition(
private readonly BindingMode _bindingMode; Control target,
private readonly Control _target; PerspexProperty targetProperty,
private readonly PerspexProperty _targetProperty; string sourcePropertyPath,
BindingMode bindingMode)
public XamlBindingDefinition(Control target, PerspexProperty targetProperty, PropertyPath sourcePropertyPath, BindingMode bindingMode)
{ {
_target = target; Target = target;
_targetProperty = targetProperty; TargetProperty = targetProperty;
_sourcePropertyPath = sourcePropertyPath; SourcePropertyPath = sourcePropertyPath;
_bindingMode = bindingMode; BindingMode = bindingMode;
} }
public Control Target => _target; public Control Target { get; }
public PerspexProperty TargetProperty => _targetProperty; public PerspexProperty TargetProperty { get; }
public PropertyPath SourcePropertyPath => _sourcePropertyPath; public string SourcePropertyPath { get; }
public BindingMode BindingMode => _bindingMode; public BindingMode BindingMode { get; }
} }
} }

8
src/Markup/Perspex.Markup.Xaml/MarkupExtensions/BindingExtension.cs

@ -27,13 +27,7 @@ namespace Perspex.Markup.Xaml.MarkupExtensions
var targetPropertyName = targetProperty.Name; var targetPropertyName = targetProperty.Name;
var perspexProperty = target.GetRegisteredProperties().First(property => property.Name == targetPropertyName); var perspexProperty = target.GetRegisteredProperties().First(property => property.Name == targetPropertyName);
return new XamlBindingDefinition return new XamlBindingDefinition(target, perspexProperty, Path, Mode);
(
target,
perspexProperty,
new PropertyPath(Path),
Mode == BindingMode.Default ? BindingMode.OneWay : Mode
);
} }
/// <summary> The source path (for CLR bindings).</summary> /// <summary> The source path (for CLR bindings).</summary>

6
tests/Perspex.Markup.Xaml.UnitTests/BindingDefinitionBuilder.cs

@ -1,24 +1,22 @@
// Copyright (c) The Perspex Project. All rights reserved. // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Controls; using Perspex.Controls;
using Perspex.Markup.Xaml.DataBinding; using Perspex.Markup.Xaml.DataBinding;
using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
namespace Perspex.Xaml.Base.UnitTest namespace Perspex.Xaml.Base.UnitTest
{ {
public class BindingDefinitionBuilder public class BindingDefinitionBuilder
{ {
private readonly BindingMode _bindingMode; private readonly BindingMode _bindingMode;
private readonly PropertyPath _sourcePropertyPath; private readonly string _sourcePropertyPath;
private Control _target; private Control _target;
private PerspexProperty _targetProperty; private PerspexProperty _targetProperty;
public BindingDefinitionBuilder() public BindingDefinitionBuilder()
{ {
_bindingMode = BindingMode.Default; _bindingMode = BindingMode.Default;
_sourcePropertyPath = new PropertyPath(string.Empty); _sourcePropertyPath = string.Empty;
} }
public BindingDefinitionBuilder WithNullTarget() public BindingDefinitionBuilder WithNullTarget()

Loading…
Cancel
Save