コード例 #1
0
 //TODO: optim: dont recreate the source binding on each datacontext change, as SourcePropertyPath does not change.
 //TODO: optim: don't subscribe to the Changed event if the binding mode does not need it.
 protected override void OnDataContextChanged()
 {
     ClearPathSourceBinding();
     _sourceBinding = SourceBindingFactory.CreateBinding(DataContext, Description.SourcePropertyPath);
     if (_sourceBinding != null)
     {
         _sourceBinding.Changed += SourceBindingOnChanged;
     }
     base.OnDataContextChanged();
 }
コード例 #2
0
        private void CreateSourceBinding(object source)
        {
            _dataContext   = source;
            _sourceBinding = SourceBindingFactory.CreateBinding(source, _bindingDescription.SourcePropertyPath);

            if (NeedToObserveSourceChanges)
            {
                _sourceBinding.Changed += (sender, args) => UpdateTargetFromSource(args.IsAvailable, args.Value);
            }

            if (NeedToUpdateTargetOnBind)
            {
                // note that we expect Bind to be called on the UI thread - so no need to use RunOnUIThread here
                object currentValue;
                bool   currentIsAvailable = _sourceBinding.TryGetValue(out currentValue);
                UpdateTargetFromSource(currentIsAvailable, currentValue);
            }
        }
コード例 #3
0
        private void UpdateChildBinding()
        {
            if (_currentChildBinding != null)
            {
                _currentChildBinding.Changed -= ChildSourceBindingChanged;
                _currentChildBinding.Dispose();
                _currentChildBinding = null;
            }
            var currentValue = FieldInfo.GetValue(Source);

            if (currentValue == null)
            {
                // value will be missing... so end consumer will need to use fallback values
                return;
            }
            else
            {
                _currentChildBinding          = SourceBindingFactory.CreateBinding(currentValue, _childTokens);
                _currentChildBinding.Changed += ChildSourceBindingChanged;
            }
        }