Browse Source

Use string XamlBindingDefinition.SourcePropertyPath.

Steven Kirk 10 years ago
parent
commit
3cb479769d

+ 2 - 1
src/Markup/Perspex.Markup.Xaml/DataBinding/PerspexPropertyBinder.cs

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

+ 13 - 15
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.
 
 using Perspex.Controls;
-using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
 
 namespace Perspex.Markup.Xaml.DataBinding
 {
     public class XamlBindingDefinition
     {
-        private readonly PropertyPath _sourcePropertyPath;
-        private readonly BindingMode _bindingMode;
-        private readonly Control _target;
-        private readonly PerspexProperty _targetProperty;
-
-        public XamlBindingDefinition(Control target, PerspexProperty targetProperty, PropertyPath sourcePropertyPath, BindingMode bindingMode)
+        public XamlBindingDefinition(
+            Control target, 
+            PerspexProperty targetProperty, 
+            string sourcePropertyPath, 
+            BindingMode bindingMode)
         {
-            _target = target;
-            _targetProperty = targetProperty;
-            _sourcePropertyPath = sourcePropertyPath;
-            _bindingMode = bindingMode;
+            Target = target;
+            TargetProperty = targetProperty;
+            SourcePropertyPath = sourcePropertyPath;
+            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; }
     }
 }

+ 1 - 7
src/Markup/Perspex.Markup.Xaml/MarkupExtensions/BindingExtension.cs

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

+ 2 - 4
tests/Perspex.Markup.Xaml.UnitTests/BindingDefinitionBuilder.cs

@@ -1,24 +1,22 @@
 // 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.
 
-using System;
 using Perspex.Controls;
 using Perspex.Markup.Xaml.DataBinding;
-using Perspex.Markup.Xaml.DataBinding.ChangeTracking;
 
 namespace Perspex.Xaml.Base.UnitTest
 {
     public class BindingDefinitionBuilder
     {
         private readonly BindingMode _bindingMode;
-        private readonly PropertyPath _sourcePropertyPath;
+        private readonly string _sourcePropertyPath;
         private Control _target;
         private PerspexProperty _targetProperty;
 
         public BindingDefinitionBuilder()
         {
             _bindingMode = BindingMode.Default;
-            _sourcePropertyPath = new PropertyPath(string.Empty);
+            _sourcePropertyPath = string.Empty;
         }
 
         public BindingDefinitionBuilder WithNullTarget()