Example #1
0
        public void BindToDataContext(object dataContext)
        {
            if (dataContext == null)
            {
                return;
            }

            try
            {
                var bindingSource = new DataContextChangeSynchronizer.BindingSource(SourcePropertyPath, dataContext);
                var bindingTarget = new DataContextChangeSynchronizer.BindingTarget(Target, TargetProperty);

                _changeSynchronizer = new DataContextChangeSynchronizer(bindingSource, bindingTarget, _typeConverterProvider);

                if (BindingMode == BindingMode.TwoWay)
                {
                    _changeSynchronizer.StartUpdatingTargetWhenSourceChanges();
                    _changeSynchronizer.StartUpdatingSourceWhenTargetChanges();
                }

                if (BindingMode == BindingMode.OneWay)
                {
                    _changeSynchronizer.StartUpdatingTargetWhenSourceChanges();
                }

                if (BindingMode == BindingMode.OneWayToSource)
                {
                    _changeSynchronizer.StartUpdatingSourceWhenTargetChanges();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
Example #2
0
        public void BindToDataContext(object dataContext)
        {
            if (dataContext == null)
            {
                return;
            }

            try
            {
                var bindingSource = new DataContextChangeSynchronizer.BindingSource(SourcePropertyPath, dataContext);
                var bindingTarget = new DataContextChangeSynchronizer.BindingTarget(Target, TargetProperty);

                _changeSynchronizer = new DataContextChangeSynchronizer(bindingSource, bindingTarget, _typeConverterProvider);

                if (BindingMode == BindingMode.TwoWay)
                {
                    _changeSynchronizer.StartUpdatingTargetWhenSourceChanges();
                    _changeSynchronizer.StartUpdatingSourceWhenTargetChanges();
                }

                if (BindingMode == BindingMode.OneWay)
                {
                    _changeSynchronizer.StartUpdatingTargetWhenSourceChanges();
                }

                if (BindingMode == BindingMode.OneWayToSource)
                {
                    _changeSynchronizer.StartUpdatingSourceWhenTargetChanges();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }