コード例 #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);
            }
        }
コード例 #2
0
ファイル: XamlBinding.cs プロジェクト: healtech/Perspex
        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);
            }
        }