コード例 #1
0
 private static void AssertValueSource(ValueSource valueSource, bool isCurrent = false, bool isExpression = false, BaseValueSource baseValueSource = BaseValueSource.Local)
 {
     Assert.AreEqual(isCurrent, valueSource.IsCurrent);
     Assert.AreEqual(isExpression, valueSource.IsExpression);
     Assert.AreEqual(baseValueSource, valueSource.BaseValueSource);
 }
コード例 #2
0
        private void Update()
        {
            if (ignoreUpdate)
                return;

            this.isLocallySet = false;
            this.isInvalidBinding = false;
            this.isDatabound = false;

            DependencyProperty dp = this.DependencyProperty;
            DependencyObject d = target as DependencyObject;

            if (SnoopModes.MultipleDispatcherMode && d != null && d.Dispatcher != this.Dispatcher)
                return;

            if (dp != null && d != null)
            {
                if (d.ReadLocalValue(dp) != DependencyProperty.UnsetValue)
                    this.isLocallySet = true;

                BindingExpressionBase expression = BindingOperations.GetBindingExpressionBase(d, dp);
                if (expression != null)
                {
                    this.isDatabound = true;

                    if (expression.HasError || expression.Status != BindingStatus.Active)
                    {
                        this.isInvalidBinding = true;

                        StringBuilder builder = new StringBuilder();
                        StringWriter writer = new StringWriter(builder);
                        TextWriterTraceListener tracer = new TextWriterTraceListener(writer);
                        PresentationTraceSources.DataBindingSource.Listeners.Add(tracer);

                        // reset binding to get the error message.
                        ignoreUpdate = true;
                        d.ClearValue(dp);
                        BindingOperations.SetBinding(d, dp, expression.ParentBindingBase);
                        ignoreUpdate = false;

                        // this needs to happen on idle so that we can actually run the binding, which may occur asynchronously.
                        Dispatcher.BeginInvoke
                        (
                            DispatcherPriority.ApplicationIdle,
                            new DispatcherOperationCallback
                            (
                                delegate(object source)
                                {
                                    bindingError = builder.ToString();
                                    this.OnPropertyChanged("BindingError");
                                    PresentationTraceSources.DataBindingSource.Listeners.Remove(tracer);
                                    writer.Close();
                                    return null;
                                }
                            ),
                            null
                        );
                    }
                    else
                    {
                        bindingError = string.Empty;
                    }
                }

                this.valueSource = DependencyPropertyHelper.GetValueSource(d, dp);
            }

            this.OnPropertyChanged("IsLocallySet");
            this.OnPropertyChanged("IsInvalidBinding");
            this.OnPropertyChanged("StringValue");
            this.OnPropertyChanged("DescriptiveValue");
            this.OnPropertyChanged("IsDatabound");
            this.OnPropertyChanged("IsExpression");
            this.OnPropertyChanged("IsAnimated");
            this.OnPropertyChanged("ValueSource");
        }
コード例 #3
0
    internal static bool IsValueSourceHazardingCellRecycling( ValueSource valueSource )
    {
      switch( valueSource.BaseValueSource )
      {
        case BaseValueSource.Local:
        case BaseValueSource.ParentTemplate:
        case BaseValueSource.ParentTemplateTrigger:
        case BaseValueSource.Unknown:
          return true;

        default:
          return false;
      }
    }