private static void FigureBinding(PropertyBinding binding, string componentPathPropertyName, string eventPropertyName, UnityAction handler)
    {
        var sobj       = new SerializedObject(binding);
        var unityEvent = GetEventValue(sobj, componentPathPropertyName, eventPropertyName);

        if (unityEvent != null)
        {
            cachedBindings.Add(binding);
            var eventCount = unityEvent.GetPersistentEventCount();

            for (var idx = 0; idx < eventCount; idx++)
            {
                var perTarget = unityEvent.GetPersistentTarget(idx);
                // if we find a duplicate event skip over adding it
                if (perTarget == binding)
                {
                    return;
                }
            }

            UnityEditor.Events.UnityEventTools.AddVoidPersistentListener(unityEvent, handler);
        }

        sobj.ApplyModifiedProperties();
    }
    private static void BuildPaths(PropertyBinding binding, StringBuilder sw)
    {
        var sobj = new SerializedObject(binding);

        BuildPath(sobj.FindProperty("_target"), sw);
        BuildPath(sobj.FindProperty("_source"), sw);
    }
예제 #3
0
        static string GetDefaultValueString(PropertyBinding propertyBinding)
        {
            switch (propertyBinding.ExposedType)
            {
            case WinCompData.MetaData.PropertySetValueType.Color:
                var color    = (WinCompData.Wui.Color)propertyBinding.DefaultValue;
                var colorHex = $"#{color.Hex}";
                return(color.TryGetFriendlyName(out var colorName)
                        ? $"{colorHex} {colorName}"
                        : colorHex);

            case WinCompData.MetaData.PropertySetValueType.Scalar:
                return(((float)propertyBinding.DefaultValue).ToString());

            case WinCompData.MetaData.PropertySetValueType.Vector2:
                return(((Vector2)propertyBinding.DefaultValue).ToString());

            case WinCompData.MetaData.PropertySetValueType.Vector3:
                return(((Vector3)propertyBinding.DefaultValue).ToString());

            case WinCompData.MetaData.PropertySetValueType.Vector4:
                return(((Vector4)propertyBinding.DefaultValue).ToString());

            default:
                throw new InvalidOperationException();
            }
        }
    void OnEnable()
    {
        _refreshed = false;
        _bindingClass = target as PropertyBinding;

        _sourceIndex = _bindingClass.SourcePropertyIndex;
        _targetIndex = _bindingClass.TargetPropertyIndex;
        _formatString = _bindingClass.FormatString;

        RefreshSourceProperties();

        if (_sourceProperties.Count != 0)
        {
            if (_sourceIndex >= _sourceProperties.Count) _sourceIndex = 0;
            _bindingClass.SourceProperty = _sourceProperties[_sourceIndex];
            _bindingClass.SourcePropertyName = _sourceProperties[_sourceIndex].Name;

            _sourcePropertiesNames = _sourceProperties.Select(p => p.Name).ToArray();

            RefreshTargetProperties();
            if (_targetProperties.Count != 0)
            {
                if (_targetIndex >= _targetProperties.Count) _targetIndex = 0;
                _bindingClass.TargetProperty = _targetProperties[_targetIndex];
                _bindingClass.TargetPropertyName = _targetProperties[_targetIndex].Name;

                _targetPropertiesNames = _targetProperties.Select(p => p.Name).ToArray();
                _refreshed = true;
            }
        }
    }
 public ViewVisibilityBinding(View target, INotifyPropertyChanged sourceObject, string sourceProperty, IBindingConverter<bool?, ViewStates> converter)
     : base(target)
 {
     _target = target;
     var valueConverter = converter != null ? converter : new VisibleIfTrueConverter();
     _propertyBinding = new PropertyBinding<ViewStates, bool?>(this, "Visibility", sourceObject, sourceProperty, valueConverter);
 }
예제 #6
0
 private void OnEnable()
 {
     _binding = target as PropertyBinding;
     _sourceTypeCollection = new TypeCollection <INotifyPropertyChanged>();
     _sourceProperties     = new MemberCollection <PropertyInfo>(_binding.SourceType, MemberFilters.SourceProperties);
     _targetProperties     = new MemberCollection <PropertyInfo>(_binding.TargetType, MemberFilters.TargetProperties);
 }
예제 #7
0
    static void FigureViewBinding(PropertyBinding binding)
    {
        // Don't register for the target event that indicates the property has changed if the value from the target never flows back to the source.
        if (!binding.Mode.IsSourceBoundToTarget())
        {
            return;
        }

        var sobj     = new SerializedObject(binding);
        var vevValue = GetViewEventValue(sobj);

        if (vevValue != null)
        {
            cachedBindings.Add(binding);
            var eventCount = vevValue.GetPersistentEventCount();

            for (var idx = 0; idx < eventCount; idx++)
            {
                var perTarget = vevValue.GetPersistentTarget(idx);
                // if we find a duplicate event skip over adding it
                if (perTarget == binding)
                {
                    return;
                }
            }

            UnityEditor.Events.UnityEventTools.AddVoidPersistentListener(vevValue, binding.ApplyVToVM);
        }

        sobj.ApplyModifiedProperties();
    }
예제 #8
0
        protected override void OnModelPropertyChanged(string propertyName)
        {
            if (propertyName == "Model")
            {
                OnConfigChanged(this, EventArgs.Empty);
            }
            else if (propertyName == "Presentation")
            {
                if (myPresentation == Model.Presentation)
                {
                    return;
                }

                myPresentation = Model.Presentation;

                myPresentation.GetModule <INodeMaskModule>().AutoHideAllNodesForShowMasks = true;

                if (myPresentation.Graph.Nodes.Count() > DotToolLayoutEngine.FastRenderingNodeCountLimit)
                {
                    new ChangeClusterFolding(myPresentation)
                    .FoldUnfoldAllClusters();
                }

                var graphLayoutModule = myPresentation.GetModule <IGraphLayoutModule>();
                graphLayoutModule.Algorithm = LayoutAlgorithm;
                PropertyBinding.Bind(() => LayoutAlgorithm, () => graphLayoutModule.Algorithm);

                RaisePropertyChanged(nameof(IsEnabled));
            }
        }
예제 #9
0
        /// <summary>
        /// Adding new customer or editing/deleting existing one.
        /// </summary>
        /// <param name="mode">Window mode.</param>
        public ModifyObjectWindow(WindowMode mode, PropertyBinding property)
        {
            winMode     = mode;
            contentType = property;
            InitializeComponent();
            switch (mode)
            {
            case WindowMode.EDIT:
            {
                Title            = "Edycja";
                InfoTextBox.Text = ObjectsListWindow.SelectedObj ?? "";
                break;
            }

            case WindowMode.ADD:
            {
                Title = "Dodawanie";
                LeftButton.Visibility = Visibility.Collapsed;
                RightButton.Content   = "Dodaj";
                break;
            }

            default:
                break;
            }
        }
        internal static void HandleViewValueChanged <TView, TArgs, TNewValue>(
            PropertyBinding propertyBinding,
            Func <TView, TArgs, TNewValue> newValueFunc,
            object dataContext,
            TArgs args)
            where TView : View
        {
            try
            {
                propertyBinding.PreventUpdateForTargetProperty = true;
                var rawValue = newValueFunc((TView)propertyBinding.View, args);

                UpdateSourceProperty(propertyBinding.SourceProperty,
                                     dataContext,
                                     rawValue,
                                     propertyBinding.Converter,
                                     propertyBinding.ConverterParameter);
            }
            catch (Exception ex)
            {
                /* TODO: log exception */
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
            finally
            {
                propertyBinding.PreventUpdateForTargetProperty = false;
            }
        }
        internal static void HandleViewValueChanged(
            PropertyBinding propertyBinding,
            object dataContext)
        {
            try
            {
                propertyBinding.PreventUpdateForTargetProperty = true;

                var newValue = propertyBinding.TargetProperty.GetValue(propertyBinding.View);

                UpdateSourceProperty(propertyBinding.SourceProperty, dataContext, newValue,
                                     propertyBinding.Converter, propertyBinding.ConverterParameter);
            }
            catch (Exception ex)
            {
                /* TODO: log exception */
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
            finally
            {
                propertyBinding.PreventUpdateForTargetProperty = false;
            }
        }
예제 #12
0
    static void FigureViewBinding(PropertyBinding binding)
    {
        if (binding.Mode == BindingMode.OneWayToTarget)
        {
            return;
        }

        var sobj     = new SerializedObject(binding);
        var vevValue = GetViewEventValue(sobj);

        if (vevValue != null)
        {
            cachedBindings.Add(binding);
            var eventCount = vevValue.GetPersistentEventCount();

            for (var idx = 0; idx < eventCount; idx++)
            {
                var perTarget = vevValue.GetPersistentTarget(idx);
                // if we find a duplicate event skip over adding it
                if (perTarget == binding)
                {
                    return;
                }
            }

            UnityEditor.Events.UnityEventTools.AddVoidPersistentListener(vevValue, binding.ApplyVToVM);
        }

        sobj.ApplyModifiedProperties();
    }
예제 #13
0
        public void PropertyOwnersMarkedForGC_BindingReleased()
        {
            WeakReference <ViewModel1> wr1 = null;
            WeakReference <ViewModel2> wr2 = null;

            new Action(() =>
            {
                var vm1 = new ViewModel1();
                var vm2 = new ViewModel2();

                wr1 = new WeakReference <ViewModel1>(vm1);
                wr2 = new WeakReference <ViewModel2>(vm2);

                PropertyBinding.Bind(() => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.TwoWay);
            })();

            EnforceGC();

            {
                ViewModel1 vm1;
                Assert.That(wr1.TryGetTarget(out vm1), Is.False);

                ViewModel2 vm2;
                Assert.That(wr2.TryGetTarget(out vm2), Is.False);
            }
        }
예제 #14
0
        protected override void OnModelPropertyChanged(string propertyName)
        {
            if (propertyName == "Model")
            {
                OnConfigChanged(this, EventArgs.Empty);
            }
            else if (propertyName == "Presentation")
            {
                if (myPresentation == Model.Presentation)
                {
                    return;
                }

                myPresentation = Model.Presentation;

                if (myPresentation.Graph.Nodes.Count() > DotToolLayoutEngine.FastRenderingNodeCountLimit)
                {
                    myPresentation.ToogleFoldingOfVisibleClusters();
                }

                var graphLayoutModule = myPresentation.GetModule <IGraphLayoutModule>();
                graphLayoutModule.Algorithm = LayoutAlgorithm;
                PropertyBinding.Bind(() => LayoutAlgorithm, () => graphLayoutModule.Algorithm);

                RaisePropertyChanged(nameof(IsEnabled));
            }
        }
예제 #15
0
 public PropertyBinding[] GetProperties(Type type)
 {
     PropertyBinding[] result = new PropertyBinding[3];
     result[0] = new MyPropertyBinding(0, typeof(int));
     result[1] = new MyPropertyBinding(1, typeof(string));
     result[2] = new MyPropertyBinding(2, typeof(DateTime));
     return(result);
 }
예제 #16
0
            protected override void Setup()
            {
                base.Setup();

                _binding = PropertyBinding.Create(
                    () => _testEntitySource.TestField1,
                    () => _testEntityTarget.TestField1);
            }
예제 #17
0
        public GenericColorEditor(string text) : base(text)
        {
            _value = new PropertyBinding <Color>();

            MaximumSize = new Size(128, 32);

            Click += onClick;
        }
예제 #18
0
        public PropertyBinding Add(PropertyInfo info, object target)
        {
            Log.Debug($"Attach [{this.Id}] {target}.{info.Name}");
            var binding = new PropertyBinding(info, target);

            this.Bindings.Add(binding);

            return(binding);
        }
예제 #19
0
            protected override void Setup()
            {
                base.Setup();

                _binding = PropertyBinding.Create(
                    () => _testEntitySource.TestField1,
                    () => _testEntityTarget.TestField1,
                    PropertyBindingDirection.TwoWayResetTarget);
            }
    private static void FigureTargetBinding(PropertyBinding binding)
    {
        // Don't register for the target event that indicates the property has changed if the value from the target never flows back to the source.
        if (!binding.Mode.IsSourceBoundToTarget())
        {
            return;
        }

        FigureBinding(binding, "_target", "_targetEvent", binding.UpdateSource);
    }
예제 #21
0
 public void Close_MultipleCalls_DoesNotThrow()
 {
     var subject = new PropertyBinding<int, float>(
         BindingType.OneWayToSource,
         _dependencyPropertyMock.Object,
         _notifyingObjectMock.Object,
         _converterMock.Object);
     subject.Close();
     Assert.DoesNotThrow(() => subject.Close());
 }
예제 #22
0
        public void OneWayToSourceBinding_ChangesOnTargetNotSyncedtoSource()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            PropertyBinding.Bind(() => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.OneWayToSource);

            vm1.PrimaryValue = 42;
            Assert.That(vm2.SecondaryValue, Is.Not.EqualTo(42));
        }
예제 #23
0
        public GenericBindingCheckBox(string Text) : base()
        {
            ApplicationSettings.SkinControl(this);

            _value = new PropertyBinding <bool>();

            this.Text = Text;

            CheckedChanged += Check2Change;
        }
예제 #24
0
        public Toolbar(ILayout parent, int defaultIndex, string[] names) : base(parent)
        {
            mIndexProperty = new PropertyBinding <int, IToolbar>(this, newValue =>
            {
                mIndex = newValue;
            });

            mNames = names;
            mIndex = defaultIndex;
        }
예제 #25
0
        public void Close_MultipleCalls_DoesNotThrow()
        {
            var subject = new PropertyBinding <int, float>(
                BindingType.OneWayToSource,
                _dependencyPropertyMock.Object,
                _notifyingObjectMock.Object,
                _converterMock.Object);

            subject.Close();
            Assert.DoesNotThrow(() => subject.Close());
        }
예제 #26
0
        internal NavigationNode Create(IStoreItem model, NavigationNode parent)
        {
            var node = new NavigationNode(this);

            node.Model  = model;
            node.Parent = parent;

            PropertyBinding.Observe(() => node.IsSelected, myOnSelectionChanged);

            return(node);
        }
예제 #27
0
        public void PropertyBindingWithStringTest()
        {
            TestClass       o       = new TestClass();
            PropertyBinding binding = new PropertyBinding(o, "IntProperty");

            o.IntProperty = 1907;
            Assert.AreEqual(o.IntProperty, binding.GetValue());

            binding.SetValue(2012);
            Assert.AreEqual(o.IntProperty, binding.GetValue());
        }
예제 #28
0
        public void PropertyBindingWithLambdaExpressionTest()
        {
            TestClass       o       = new TestClass();
            PropertyBinding binding = new PropertyBinding(o, () => o.IntProperty);

            o.IntProperty = 1907;
            Assert.AreEqual(o.IntProperty, binding.GetValue());

            binding.SetValue(2012);
            Assert.AreEqual(o.IntProperty, binding.GetValue());
        }
예제 #29
0
 static public int get_direction(IntPtr l)
 {
     try {
         PropertyBinding self = (PropertyBinding)checkSelf(l);
         pushValue(l, true);
         pushEnum(l, (int)self.direction);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #30
0
 static public int UpdateTarget(IntPtr l)
 {
     try {
         PropertyBinding self = (PropertyBinding)checkSelf(l);
         self.UpdateTarget();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #31
0
파일: Toggle.cs 프로젝트: DiazGames/oneGame
        internal Toggle(ILayout parent) : base(parent)
        {
            textProperty = new PropertyBinding <string, IToggle>(
                this,
                value => text = value
                );

            onProperty = new PropertyBinding <bool, IToggle>(
                this,
                value => on = value
                );
        }
예제 #32
0
 static public int get_target(IntPtr l)
 {
     try {
         PropertyBinding self = (PropertyBinding)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.target);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #33
0
        public void TwoWayBinding_ChangesOnEitherEndSyncedToTheOtherOne()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            PropertyBinding.Bind(() => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.TwoWay);

            vm1.PrimaryValue = 42;
            Assert.That(vm2.SecondaryValue, Is.EqualTo(42));

            vm2.SecondaryValue = 24;
            Assert.That(vm1.PrimaryValue, Is.EqualTo(24));
        }
예제 #34
0
        public void Close_SourceUpdated_TargetNotUpdated()
        {
            _converterMock.Setup(mock => mock.CanConvert(It.IsAny<int>(), It.IsAny<CultureInfo>()));
            var subject = new PropertyBinding<int, float>(
                BindingType.OneWayToSource,
                _dependencyPropertyMock.Object,
                _notifyingObjectMock.Object,
                _converterMock.Object);

            subject.Close();
            _notifyingObjectMock.Raise(mock => mock.PropertyChanged += null, new PropertyChangedEventArgs<int>(0, 1));

            _converterMock.Verify(mock => mock.CanConvert(It.IsAny<int>(), It.IsAny<CultureInfo>()), Times.Never);
        }
예제 #35
0
파일: Control.binding.cs 프로젝트: Exe0/Eto
		/// <summary>
		/// Adds a new binding with the control and the the control's current data context 
		/// </summary>
		/// <remarks>
		/// This binds to a property of the <see cref="Control.DataContext"/>, which will return the topmost value
		/// up the control hierarchy.  For example, you can set the DataContext of your form or panel, and then bind to properties
		/// of that context on any of the child controls such as a text box, etc.
		/// </remarks>
		/// <param name="controlPropertyName">Property on the control to update</param>
		/// <param name="dataContextPropertyName">Property on the control's <see cref="Control.DataContext"/> to bind to the control</param>
		/// <param name="mode">Mode of the binding</param>
		/// <param name="defaultControlValue">Default value to set to the control when the value from the DataContext is null</param>
		/// <param name="defaultContextValue">Default value to set to the DataContext property when the control value is null</param>
		/// <returns>A new instance of the DualBinding class that is used to control the binding</returns>
		public DualBinding Bind(string controlPropertyName, string dataContextPropertyName, DualBindingMode mode = DualBindingMode.TwoWay, object defaultControlValue = null, object defaultContextValue = null)
		{
			var dataContextBinding = new PropertyBinding(dataContextPropertyName);
			var controlBinding = new PropertyBinding(controlPropertyName);
			return Bind(controlBinding, dataContextBinding, mode, defaultControlValue, defaultContextValue);
		}
예제 #36
0
		public ImageViewCell (string property)
			: this()
		{
			Binding = new PropertyBinding (property);
		}
 /// <summary>Binds this property (the target) to the given property (the source).</summary>
 /// <param name="source">The source property to bind to.</param>
 /// <param name="mode">The binding mode.</param>
 /// <remarks>
 ///     The property can only be bound to one source.  
 ///     Calling this method with another source disposes of the original binding.
 /// </remarks>
 public void BindTo(PropertyRef source, BindingMode mode)
 {
     ClearBinding();
     propertyBinding = new PropertyBinding(source, this, mode);
 }
예제 #38
0
        public void Ctor_TwoWayBindingSourceChanged_CanConvertCalled()
        {
            const int source = 52;
            var culture = CultureInfo.InvariantCulture;

            _converterMock.Setup(mock => mock.CanConvert(source, culture));

            using (var subject = new PropertyBinding<int, float>(
                BindingType.TwoWay,
                _dependencyPropertyMock.Object,
                _notifyingObjectMock.Object,
                _converterMock.Object))
            {
                subject.Culture = culture;
                _notifyingObjectMock.Raise(mock => mock.PropertyChanged += null, new PropertyChangedEventArgs<int>(0, source));
            }

            _converterMock.Verify(mock => mock.CanConvert(source, culture), Times.Once());
        }
예제 #39
0
        public void Ctor_TwoWayBindingTargetChanged_CanConvertBackCalled()
        {
            const float target = 52.53f;
            var culture = CultureInfo.InvariantCulture;

            _converterMock.Setup(mock => mock.CanConvertBack(target, culture));

            using (var subject = new PropertyBinding<int, float>(
                BindingType.TwoWay,
                _dependencyPropertyMock.Object,
                _notifyingObjectMock.Object,
                _converterMock.Object))
            {
                subject.Culture = culture;
                _dependencyPropertyMock.Raise(mock => mock.PropertyChanged += null, new PropertyChangedEventArgs<float>(0, target));
            }

            _converterMock.Verify(mock => mock.CanConvertBack(target, culture), Times.Once());
        }
예제 #40
0
파일: ImageTextCell.cs 프로젝트: mhusen/Eto
		/// <summary>
		/// Initializes a new instance of the <see cref="Eto.Forms.ImageTextCell"/> class when binding to properties via reflection.
		/// </summary>
		/// <param name="imageProperty">Name of the image property in the data item.</param>
		/// <param name="textProperty">Name of the text property in the data item.</param>
		public ImageTextCell(string imageProperty, string textProperty)
		{
			ImageBinding = new PropertyBinding<Image>(imageProperty);
			TextBinding = new PropertyBinding<string>(textProperty);
		}
 public ViewClickableBinding(View target, INotifyPropertyChanged sourceObject, string sourceProperty, IBindingConverter<bool, bool> converter)
     : base(target)
 {
     _target = target;
     _propertyBinding = new PropertyBinding<bool, bool>(this, "Clickable", sourceObject, sourceProperty, converter);
 }
예제 #42
0
		public ImageTextCell (string imageProperty, string textProperty)
			: this()
		{
			ImageBinding = new PropertyBinding(imageProperty);
			TextBinding = new PropertyBinding(textProperty);
		}
예제 #43
0
		public TextBoxCell (string property)
			: this()
		{
			Binding = new PropertyBinding (property);
		}
예제 #44
0
        public void Ctor_OneWayToSourceBindingAndCanConvertBack_ConvertBackCalled()
        {
            const float target = 52.4f;
            var culture = CultureInfo.InvariantCulture;

            _converterMock.Setup(mock => mock.CanConvertBack(It.IsAny<float>(), It.IsAny<CultureInfo>())).Returns(true);
            _converterMock.Setup(mock => mock.ConvertBack(target, culture));

            using (var subject = new PropertyBinding<int, float>(
                BindingType.OneWayToSource,
                _dependencyPropertyMock.Object,
                _notifyingObjectMock.Object,
                _converterMock.Object))
            {
                subject.Culture = culture;
                _dependencyPropertyMock.Raise(mock => mock.PropertyChanged += null, new PropertyChangedEventArgs<float>(0, target));
            }

            _converterMock.Verify(mock => mock.ConvertBack(target, culture), Times.Once());
        }