示例#1
0
        private void OnForegroundPropertyChanged(DependencyPropertyChangedEventArgs args)
        {
            var baseValueSource = DependencyPropertyHelper.GetValueSource(this, args.Property).BaseValueSource;

            _isForegroundDefaultOrInherited = baseValueSource <= BaseValueSource.Inherited;
            UpdateShouldInheritForegroundFromVisualParent();
        }
        public WorkflowEditorOverlayView(WorkflowEditorOverlayViewModel vm, IRegionManager regionManager)
        {
            _regionManager = regionManager;
            DataContext    = vm;
            InitializeComponent();
            // Prism doesn't want to register the region properly so we do it by hand
            if (!_isRegistered)
            {
                Prism.Regions.RegionManager.SetRegionManager(ContentControl, _regionManager);
                _isRegistered = true;
            }

            vm.UpdateHelpTopic = () =>
            {
                var dependencyObject = ContentControl.GetChildObjects().FirstOrDefault();
                if (dependencyObject == null)
                {
                    return;
                }

                var valueSource = DependencyPropertyHelper.GetValueSource(dependencyObject, HelpProvider.HelpTopicProperty);
                if (valueSource.BaseValueSource != BaseValueSource.Default)
                {
                    SetValue(HelpProvider.HelpTopicProperty, dependencyObject.GetValue(HelpProvider.HelpTopicProperty));
                }
            };
        }
        /// <summary>
        /// Sets the value of the specified target object and property, based on the specified source property.
        /// </summary>
        /// <param name="sourceProperty">The source property.</param>
        /// <param name="targetElement">The target element.</param>
        /// <param name="targetProperty">The target property.</param>
        protected virtual void ApplyValue(DependencyProperty sourceProperty, FrameworkElement targetElement, DependencyProperty targetProperty)
        {
            if (sourceProperty == null)
            {
                throw new ArgumentNullException("sourceProperty");
            }
            else if (targetElement == null)
            {
                throw new ArgumentNullException("targetElement");
            }
            else if (targetProperty == null)
            {
                throw new ArgumentNullException("targetProperty");
            }

            // 8/22/2011 - If the property is not set on the column, then do not pass down to the element (10F-15E35C2E-480E)
            // 1/27/2012 - Fixed issue with column default that differ from the column not getting passed down properly (197-16B573BD-0301)
            if (DependencyPropertyHelper.GetValueSource(this, sourceProperty).BaseValueSource == BaseValueSource.Default &&
                DefaultValuesEqual(sourceProperty.GetMetadata(this), targetProperty.GetMetadata(targetElement)))
            {
                targetElement.ClearValue(targetProperty);
            }
            else
            {
                targetElement.SetValue(targetProperty, this.GetValue(sourceProperty));
            }
        }
示例#4
0
        private void UpdateValue(DependencyObject d, DependencyProperty dp)
        {
            if (d.ReadLocalValue(dp) != DependencyProperty.UnsetValue)
            {
                IsLocallySet = true;
            }

            ValueSource = DependencyPropertyHelper.GetValueSource(d, dp);

            var expression = BindingOperations.GetBindingExpressionBase(d, dp);

            if (expression == null)
            {
                return;
            }

            IsDatabound = true;

            if (expression.HasError || expression.Status != BindingStatus.Active)
            {
                SetBindingError(d, dp, expression);
            }
            else
            {
                BindingError = string.Empty;
            }
        }
示例#5
0
        private static void ScrollViewer_Loaded(object sender, RoutedEventArgs e)
        {
            var sv = (ScrollViewer)sender;

            sv.Loaded -= ScrollViewer_Loaded;

            if (sv.TemplatedParent == null)
            {
                var valueSource = DependencyPropertyHelper.GetValueSource(sv, ScrollViewer.PanningModeProperty).BaseValueSource;
                if (valueSource == BaseValueSource.Default)
                {
                    sv.SetBinding(ScrollViewer.PanningModeProperty, new MultiBinding
                    {
                        Bindings =
                        {
                            new Binding
                            {
                                Path           = new PropertyPath(ScrollViewer.ComputedHorizontalScrollBarVisibilityProperty),
                                RelativeSource = new RelativeSource(RelativeSourceMode.Self)
                            },
                            new Binding
                            {
                                Path           = new PropertyPath(ScrollViewer.ComputedVerticalScrollBarVisibilityProperty),
                                RelativeSource = new RelativeSource(RelativeSourceMode.Self)
                            },
                        },
                        Converter = new PanningModeConverter()
                    });
                }
            }
        }
示例#6
0
        // Token: 0x060048D9 RID: 18649 RVA: 0x0014AA20 File Offset: 0x00148C20
        public static object GetCoercedTransferPropertyValue(DependencyObject baseObject, object baseValue, DependencyProperty baseProperty, DependencyObject parentObject, DependencyProperty parentProperty, DependencyObject grandParentObject, DependencyProperty grandParentProperty)
        {
            object result = baseValue;

            if (DataGridHelper.IsPropertyTransferEnabled(baseObject, baseProperty))
            {
                BaseValueSource baseValueSource = DependencyPropertyHelper.GetValueSource(baseObject, baseProperty).BaseValueSource;
                if (parentObject != null)
                {
                    ValueSource valueSource = DependencyPropertyHelper.GetValueSource(parentObject, parentProperty);
                    if (valueSource.BaseValueSource > baseValueSource)
                    {
                        result          = parentObject.GetValue(parentProperty);
                        baseValueSource = valueSource.BaseValueSource;
                    }
                }
                if (grandParentObject != null)
                {
                    ValueSource valueSource2 = DependencyPropertyHelper.GetValueSource(grandParentObject, grandParentProperty);
                    if (valueSource2.BaseValueSource > baseValueSource)
                    {
                        result          = grandParentObject.GetValue(grandParentProperty);
                        baseValueSource = valueSource2.BaseValueSource;
                    }
                }
            }
            return(result);
        }
示例#7
0
        protected void OnForegroundPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            var baseValueSource = DependencyPropertyHelper.GetValueSource(this, e.Property).BaseValueSource;

            isForegroundPropertyDefaultOrInherited = baseValueSource <= BaseValueSource.Inherited;
            UpdateInheritsForegroundFromVisualParent();
        }
        /// <summary>
        /// Deselects the selection box if the selection box
        /// is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectionBox_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (selectAreaMode)
            {
                // Capture and track the mouse.
                mouseDown         = true;
                mouseDownPosition = e.GetPosition(MyCanvas);
                ImageViewer.CaptureMouse();

                coordAtMouseDown = new Point(float.Parse(XPosition.Text), float.Parse(YPosition.Text));

                // Initial placement of the drag selection box.
                Canvas.SetLeft(SelectionBox, mouseDownPosition.X);
                Canvas.SetTop(SelectionBox, mouseDownPosition.Y);
                SelectionBox.Width  = 0;
                SelectionBox.Height = 0;

                // Make the drag selection box visible.
                SelectionBox.Visibility = Visibility.Visible;

                // If the dash border for the selection box is not already animated,
                // animate it.
                if (!(DependencyPropertyHelper.GetValueSource(SelectionBox, Rectangle.StrokeDashOffsetProperty).IsAnimated))
                {
                    storyBoard.Begin();
                }
            }
        }
示例#9
0
        protected override IList <Issue> AnalyzeInternal(TreeItem treeItem)
        {
            var issues           = new List <Issue>();
            var dependencyObject = treeItem.Instance as DependencyObject;

            if (dependencyObject == null)
            {
                return(issues);
            }

            foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(dependencyObject.GetType()))
            {
                var dpd = DependencyPropertyDescriptor.FromProperty(property);
                if (dpd != null && !dpd.IsReadOnly && dpd.PropertyType == typeof(Brush))
                {
                    var localValue  = dependencyObject.ReadLocalValue(dpd.DependencyProperty);
                    var valueSource = DependencyPropertyHelper.GetValueSource(dependencyObject, dpd.DependencyProperty);
                    if (valueSource.BaseValueSource == BaseValueSource.Local && !valueSource.IsExpression)
                    {
                        if (localValue is Brush && localValue != Brushes.Transparent)
                        {
                            issues.Add(
                                new Issue("LocalBrush",
                                          string.Format(
                                              "Property {0} contains the local brush {1}. Prevent local brushes to keep the design maintainable.",
                                              dpd.DisplayName, localValue), IssueSeverity.Message,
                                          IssueCategory.Maintainability, treeItem, dpd));
                        }
                    }
                }
            }

            return(issues);
        }
示例#10
0
        public static void SetBindingToAncestorIfDefault(this DependencyObject source, DependencyProperty property)
        {
            if (!source.IsDefaultValue(property))
            {
                return;
            }

            var keyColumnWidthPropertySource = DependencyPropertyHelper.GetValueSource(source, property);

            if (keyColumnWidthPropertySource.BaseValueSource > BaseValueSource.Style)
            {
                return;
            }
            if (keyColumnWidthPropertySource.IsExpression)
            {
                return;
            }

            var result = source.TraverseVisualParentWhere(o => o.IsDefaultValue(property));

            if (result == null)
            {
                return;
            }

            BindingOperations.SetBinding(source,
                                         property,
                                         new Binding
            {
                Source = result,
                Path   = new PropertyPath(property),
                Mode   = BindingMode.TwoWay
            });
        }
示例#11
0
        internal static CultureInfo GetCultureForElement(DependencyObject element)
        {
            if (DependencyPropertyHelper.GetValueSource(element, FrameworkElement.LanguageProperty).BaseValueSource == BaseValueSource.Default)
            {
                return(CultureInfo.CurrentCulture);
            }

            XmlLanguage language = (XmlLanguage)element.GetValue(FrameworkElement.LanguageProperty);

            if (language == null || language == XmlLanguage.Empty)
            {
                return(CultureInfo.CurrentCulture);
            }

            if (Current._cultureCache == null)
            {
                Current._cultureCache = new Dictionary <XmlLanguage, CultureInfo>();
            }

            CultureInfo result;

            if (!Current._cultureCache.TryGetValue(language, out result))
            {
                Current._cultureCache[language] = result = language.GetCultureInfo() ?? CultureInfo.CurrentCulture;
            }

            return(result);
        }
示例#12
0
        public static void BindingPropertyIfUndefaultAndUninherited(FrameworkElement element,
                                                                    DependencyProperty targetProperty,
                                                                    object source,
                                                                    DependencyProperty sourceProperty,
                                                                    IValueConverter converter   = null,
                                                                    BindingMode mode            = BindingMode.Default,
                                                                    UpdateSourceTrigger trigger = UpdateSourceTrigger.Default)
        {
            var baseValueSource = DependencyPropertyHelper.GetValueSource(element, targetProperty).BaseValueSource;

            if (baseValueSource != BaseValueSource.Default && baseValueSource != BaseValueSource.Inherited)
            {
                return;
            }
            var binding = new Binding()
            {
                Path                = new PropertyPath(sourceProperty),
                Source              = source,
                Mode                = mode,
                Converter           = converter,
                UpdateSourceTrigger = trigger
            };

            element.SetBinding(targetProperty, binding);
        }
        /// <summary>
        /// Sets the value of the <paramref name="dependencyProperty"/> only if it hasn't been explicitly set.
        /// </summary>
        /// <typeparam name="T"> The type of the <see cref="DependencyProperty"/>. </typeparam>
        /// <param name="dependencyObject"> The <see cref="DependencyObject"/> holding the <paramref name="dependencyProperty"/>. </param>
        /// <param name="dependencyProperty"> The <see cref="DependencyProperty"/>. </param>
        /// <param name="value"> The new value. </param>
        /// <returns> <c>True</c> on success, otherwise <c>False</c>. </returns>
        /// <remarks> https://github.com/kmcginnes/SpicyTaco.AutoGrid (v1.2.29) </remarks>
        public static bool SetIfDefault <T>(this DependencyObject dependencyObject, DependencyProperty dependencyProperty, T value)
        {
            if (dependencyObject == null)
            {
                throw new ArgumentNullException(nameof(dependencyObject));
            }
            if (dependencyProperty == null)
            {
                throw new ArgumentNullException(nameof(dependencyProperty));
            }

            // Check the type.
            if (!dependencyProperty.PropertyType.IsAssignableFrom(typeof(T)))
            {
                throw new ArgumentException($"Expected {dependencyProperty.Name} to be of type {typeof(T).Name} but was {dependencyProperty.PropertyType}");
            }

            // Check if the dependency property still has its default value.
            if (DependencyPropertyHelper.GetValueSource(dependencyObject, dependencyProperty).BaseValueSource != BaseValueSource.Default)
            {
                return(false);
            }

            // Set the value.
            dependencyObject.SetValue(dependencyProperty, value);
            return(true);
        }
        private static void Window_ContentRendered(object sender, EventArgs e)
        {
            Window actualHeight = sender as Window;

            if (actualHeight == null)
            {
                return;
            }
            actualHeight.ContentRendered -= new EventHandler(WindowAutoSizeBehavior.Window_ContentRendered);
            actualHeight.Height           = actualHeight.ActualHeight;
            if (actualHeight.SizeToContent.HasFlag(SizeToContent.Height) && DependencyPropertyHelper.GetValueSource(actualHeight, FrameworkElement.MinHeightProperty).BaseValueSource != BaseValueSource.Local)
            {
                actualHeight.MinHeight = actualHeight.ActualHeight;
            }
            if (actualHeight.SizeToContent.HasFlag(SizeToContent.Height) && DependencyPropertyHelper.GetValueSource(actualHeight, FrameworkElement.MaxHeightProperty).BaseValueSource != BaseValueSource.Local)
            {
                actualHeight.MaxHeight = actualHeight.ActualHeight;
            }
            actualHeight.Width = actualHeight.ActualWidth;
            if (actualHeight.SizeToContent.HasFlag(SizeToContent.Width) && DependencyPropertyHelper.GetValueSource(actualHeight, FrameworkElement.MinWidthProperty).BaseValueSource != BaseValueSource.Local)
            {
                actualHeight.MinWidth = actualHeight.ActualWidth;
            }
            if (actualHeight.SizeToContent.HasFlag(SizeToContent.Width) && DependencyPropertyHelper.GetValueSource(actualHeight, FrameworkElement.MaxWidthProperty).BaseValueSource != BaseValueSource.Local)
            {
                actualHeight.MaxWidth = actualHeight.ActualHeight;
            }
            actualHeight.SizeToContent = SizeToContent.Manual;
        }
示例#15
0
        private void logItemsScroll_ScrollChanged(object sender, ScrollChangedEventArgs args)
        {
            bool cond = logItemsScroll.VerticalOffset >= logItemsScroll.ScrollableHeight - 50;

            // e.VerticalChange can actually be 0, so test for positive and negative values explicitly
            if (args.VerticalChange > 0)
            {
                // Scrolled down, can only set flag if in range
                logItemsScrolledNearEnd |= cond;
            }
            else if (args.VerticalChange < 0)
            {
                // Scrolled up, can only clear flag if out of range
                logItemsScrolledNearEnd &= cond;

                // Stop the scroll animation immediately when scrolling up
                if (DependencyPropertyHelper.GetValueSource(logItemsScrollMediator, ScrollViewerOffsetMediator.VerticalOffsetProperty).IsAnimated)
                {
                    if (logItemsScrollMediator != null)                       // Should always be true here
                    {
                        logItemsScrollMediator.StopDoubleAnimation(ScrollViewerOffsetMediator.VerticalOffsetProperty);
                        logItemsScrollPixelDc.Fire();
                    }
                }
            }
        }
示例#16
0
        public void Cancel_loading()
        {
            Env.RequestDelay = 10.Second();
            var attachment = Download();

            Assert.IsTrue(attachment.IsDownloading);
            WaitIdle();
            dispatcher.Invoke(() => {
                var attachments = ByName <ItemsControl>("CurrentItem_Value_Attachments");
                var button      = attachments.Descendants <Button>().First();
                Assert.AreEqual("downloading", button.Tag);
                InternalClick(button);
            });
            WaitIdle();
            dispatcher.Invoke(() => {
                var attachments = ByName <ItemsControl>("CurrentItem_Value_Attachments");
                var button      = attachments.Descendants <Button>().First();
                Assert.AreEqual("wait", button.Tag);
            });

            //проверяем что анимация загрузки завершилась в случае отмены
            dispatcher.Invoke(() => scheduler.Start());
            //даем возможность начать анимацию
            WaitIdle();
            dispatcher.Invoke(() => {
                var button = ByName <Button>(activeWindow, "ShowJournal");
                var p      = button.Descendants <System.Windows.Shapes.Path>().First();
                Assert.IsFalse(DependencyPropertyHelper.GetValueSource(p.RenderTransform, TranslateTransform.YProperty).IsAnimated);
            });
            Assert.AreEqual(0, shell.PendingDownloads.Count);
        }
示例#17
0
        /// <summary>Initializes a new instance of the <see cref="MainWindow" /> class.</summary>
        /// <autogeneratedoc />
        /// TODO Edit XML Comment Template for #ctor
        public MainWindow( )
        {
            InitializeComponent( );

            // SetValue (
            // AppShared.Props.LifetimeScopeProperty
            // , ( Application.Current as App )?.LifetimeScope
            // ) ;
            try
            {
                if (TryFindResource("ResolveServices") is ResolveServiceList resolveServiceList
                    )
                {
                    foreach (var resolveService in resolveServiceList)
                    {
                        var valueSource = DependencyPropertyHelper.GetValueSource(
                            resolveService
                            , Props
                            .LifetimeScopeProperty
                            );
                        var lifetimeScope = Props.GetLifetimeScope(resolveService);
                        Logger.Warn(
                            $"{resolveService.ServiceType} {lifetimeScope} {valueSource}"
                            );
                    }
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
示例#18
0
        protected override Size MeasureOverride(Size availableSize)
        {
            onPreApplyTemplate();

            Size theChildSize = new Size(this.ItemWidth, this.ItemHeight);

            object foo = DependencyPropertyHelper.GetValueSource(this, ItemHeightProperty);

            foreach (UIElement child in Children)
            {
                child.Measure(theChildSize);
            }

            int childrenPerRow;

            // Figure out how many children fit on each row
            if (availableSize.Width == Double.PositiveInfinity)
            {
                childrenPerRow = this.Children.Count;
            }
            else
            {
                childrenPerRow = Math.Max(1, (int)Math.Floor(availableSize.Width / this.ItemWidth));
            }

            // Calculate the width and height this results in
            double width  = childrenPerRow * this.ItemWidth;
            double height = this.ItemHeight * (Math.Floor((double)this.Children.Count / childrenPerRow) + 1);

            height = (height.IsRational()) ? height : 0;
            return(new Size(width, height));
        }
示例#19
0
        protected override void OnVisualParentChanged(DependencyObject oldParent)
        {
            base.OnVisualParentChanged(oldParent);
            var source = DependencyPropertyHelper.GetValueSource(this, RootVisualProperty);

            if (source.IsExpression && source.BaseValueSource == BaseValueSource.Local)
            {
                return;
            }
            if (source.BaseValueSource != BaseValueSource.Default && source.BaseValueSource != BaseValueSource.Local &&
                source.BaseValueSource != BaseValueSource.Inherited)
            {
                return;
            }

            InternalRootItems.Clear();
            var    window = Window.GetWindow(this);
            Visual v      = window;

            if (window == null)
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                for (v = (Visual)VisualParent; VisualTreeHelper.GetParent(v) != null; v = (Visual)VisualTreeHelper.GetParent(v))
                {
                    ;
                }
            }
            InternalRootItems.Add(new VisualTreeNode {
                Visual            = v,
                TransformToSource = v
            });
        }
示例#20
0
        /// <summary>
        ///     Sets the value of the <paramref name="property" /> only if it hasn't been explicitely set.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="o">The object.</param>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static bool SetIfDefault <T>(this DependencyObject o, DependencyProperty property, T value)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o", "DependencyObject cannot be null");
            }
            if (property == null)
            {
                throw new ArgumentNullException("property", "DependencyProperty cannot be null");
            }

            if (!property.PropertyType.IsAssignableFrom(typeof(T)))
            {
                throw new ArgumentException(
                          string.Format("Expected {0} to be of type {1} but was {2}",
                                        property.Name, typeof(T).Name, property.PropertyType));
            }

            if (DependencyPropertyHelper.GetValueSource(o, property).BaseValueSource == BaseValueSource.Default)
            {
                o.SetValue(property, value);

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Sets the value of the <paramref name="property"/> only if it hasn't been explicitely set.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="o">The object.</param>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static bool SetIfDefault <T>(this DependencyObject o, DependencyProperty property, T value)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o", "Object cannot be null");
            }

            if (property == null)
            {
                throw new ArgumentNullException("property", "property cannot be null");
            }

            if (!property.PropertyType.IsAssignableFrom(typeof(T)))
            {
                throw new ArgumentException("IncompatibleType");
            }

            if (DependencyPropertyHelper.GetValueSource(o, property).BaseValueSource == BaseValueSource.Default)
            {
                o.SetValue(property, value);

                return(true);
            }

            return(false);
        }
示例#22
0
        internal static void AttachBehavior(Control control)
        {
            // If the VisualStateBehavior has already been set in some way other than the default value,
            // then let that value win.
            if (DependencyPropertyHelper.GetValueSource(control, VisualStateBehavior.VisualStateBehaviorProperty).BaseValueSource == BaseValueSource.Default)
            {
                if (!_registeredKnownTypes)
                {
                    // When using the Toolkit version of VSM for WPF, the controls
                    // don't know about VSM and don't change states. Thus, these
                    // behaviors help bootstrap that behavior.
                    // In order to appear compatible with Silverlight, we can
                    // pre-register these behaviors. When moved into WPF, these
                    // behaviors should be unnecessary and this can go away.
                    _registeredKnownTypes = true;

                    // These are the known behaviors in the Toolkit.
                    RegisterControlBehavior(new ButtonBaseBehavior());
                    RegisterControlBehavior(new ToggleButtonBehavior());
                    RegisterControlBehavior(new ListBoxItemBehavior());
                    RegisterControlBehavior(new TextBoxBaseBehavior());
                    RegisterControlBehavior(new ProgressBarBehavior());
                }

                // No VisualStateBehavior has been specified, check the list of registered behaviors.
                VisualStateBehavior behavior = VisualStateBehaviorFactory.Instance.GetHandler(control.GetType());
                if (behavior != null)
                {
                    VisualStateBehavior.SetVisualStateBehavior(control, behavior);
                }
            }
        }
示例#23
0
 /// <summary>
 /// Set valut to the property is the property is not set yet
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="property"></param>
 /// <param name="value"></param>
 public static void SetValueIfDefault(this DependencyObject obj, DependencyProperty property, object value)
 {
     if (value != null && DependencyPropertyHelper.GetValueSource(obj, property).BaseValueSource == BaseValueSource.Default)
     {
         obj.SetValue(property, value);
     }
 }
            /// <summary>
            ///     Property changed callback for DataContext property
            /// </summary>
            private static void OnDataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                // Selector has a bug regarding DataContext change and SelectedItem property,
                // where if the SelectedItem due to old DataContext is a valid item in ItemsSource
                // but the SelectedItem due to new DataContext is not a valid item in ItemsSource,
                // the SelectedIndex remains that of old context instead of changing to -1.
                // This method is a workaround to that problem, since it is of high impact to DataGrid.
                TextBlockComboBox combo = (TextBlockComboBox)d;
                bool isLocalValue       = (DependencyPropertyHelper.GetValueSource(combo, SelectedItemProperty).BaseValueSource == BaseValueSource.Local);

                if (isLocalValue)
                {
                    // Clear the selection and re-apply the binding.
                    BindingBase binding = BindingOperations.GetBindingBase(combo, SelectedItemProperty);
                    if (binding != null)
                    {
                        combo.ClearValue(SelectedItemProperty);
                        DataGridPactComboBoxColumn.ApplyBinding(binding, combo, SelectedItemProperty);
                    }
                }
                else
                {
                    // Clear the selection by setting the local value
                    // and re-evaluate the property by clearing the local value.
                    combo.SelectedItem = null;
                    combo.ClearValue(SelectedItemProperty);
                }
            }
示例#25
0
        //-------------------------------------------------------------------
        //
        // Internal Methods
        //
        //-------------------------------------------------------------------

        #region Internal Methods

        /// <summary>
        /// Updates TextProperty when it is no longer in [....] with the backing store. Called by
        /// TextContainer when a change affects the text contained by this Run.
        /// </summary>
        /// <remarks>
        /// If a public TextChanged event is added, we need to raise the event only when the
        /// outermost call to this function exits.
        /// </remarks>
        internal override void OnTextUpdated()
        {
            // If the value of Run.Text comes from a local value without a binding expression, we purposely allow the
            // redundant roundtrip property set here. (SetValue on Run.TextProperty causes a TextContainer change,
            // which causes this notification, and we set the property again.) We want to avoid keeping duplicate string
            // data (both in the property system and in the backing store) when Run.Text is set, so we replace the
            // original string property value with a deferred reference. This causes an extra property changed
            // notification, but this is better than duplicating the data.

            ValueSource textPropertySource = DependencyPropertyHelper.GetValueSource(this, TextProperty);

            if (!_isInsideDeferredSet && (_changeEventNestingCount == 0 || (textPropertySource.BaseValueSource == BaseValueSource.Local &&
                                                                            !textPropertySource.IsExpression)))
            {
                _changeEventNestingCount++;
                _isInsideDeferredSet = true;
                try
                {
                    // Use a deferred reference as a performance optimization. Most of the time, no
                    // one will even be watching this property.
                    SetCurrentDeferredValue(TextProperty, new DeferredRunTextReference(this));
                }
                finally
                {
                    _isInsideDeferredSet = false;
                    _changeEventNestingCount--;
                }
            }
        }
示例#26
0
        /// <summary>
        ///   Computes changes in text alignment caused by HorizontalContentAlignment. TextAlignment has priority over HorizontalContentAlignment.
        /// </summary>
        /// <returns>
        ///   Returns the effective text alignment.
        /// </returns>
        private TextAlignment ComputedTextAlignment()
        {
            if (DependencyPropertyHelper.GetValueSource(this, HorizontalContentAlignmentProperty).BaseValueSource ==
                BaseValueSource.Local
                &&
                DependencyPropertyHelper.GetValueSource(this, TextAlignmentProperty).BaseValueSource !=
                BaseValueSource.Local)
            {
                // HorizontalContentAlignment dominates
                switch (HorizontalContentAlignment)
                {
                case HorizontalAlignment.Left:
                    return(TextAlignment.Left);

                case HorizontalAlignment.Right:
                    return(TextAlignment.Right);

                case HorizontalAlignment.Center:
                    return(TextAlignment.Center);

                case HorizontalAlignment.Stretch:
                    return(TextAlignment.Justify);
                }
            }
            return(TextAlignment);
        }
        internal void UpdateAdvanceOptionsForItem(MarkupObject markupObject, DependencyObject dependencyObject, DependencyPropertyDescriptor dpDescriptor,
                                                  out object tooltip)
        {
            tooltip = StringConstants.AdvancedProperties;

            bool isResource        = false;
            bool isDynamicResource = false;

            var markupProperty = markupObject.Properties.FirstOrDefault(p => p.Name == PropertyName);

            if (markupProperty != null)
            {
                //TODO: need to find a better way to determine if a StaticResource has been applied to any property not just a style(maybe with StaticResourceExtension)
                isResource        = typeof(Style).IsAssignableFrom(markupProperty.PropertyType);
                isDynamicResource = typeof(DynamicResourceExtension).IsAssignableFrom(markupProperty.PropertyType);
            }

            if (isResource || isDynamicResource)
            {
                tooltip = StringConstants.Resource;
            }
            else
            {
                if ((dependencyObject != null) && (dpDescriptor != null))
                {
                    if (BindingOperations.GetBindingExpressionBase(dependencyObject, dpDescriptor.DependencyProperty) != null)
                    {
                        tooltip = StringConstants.Databinding;
                    }
                    else
                    {
                        BaseValueSource bvs =
                            DependencyPropertyHelper
                            .GetValueSource(dependencyObject, dpDescriptor.DependencyProperty)
                            .BaseValueSource;

                        switch (bvs)
                        {
                        case BaseValueSource.Inherited:
                        case BaseValueSource.DefaultStyle:
                        case BaseValueSource.ImplicitStyleReference:
                            tooltip = StringConstants.Inheritance;
                            break;

                        case BaseValueSource.DefaultStyleTrigger:
                            break;

                        case BaseValueSource.Style:
                            tooltip = StringConstants.StyleSetter;
                            break;

                        case BaseValueSource.Local:
                            tooltip = StringConstants.Local;
                            break;
                        }
                    }
                }
            }
        }
示例#28
0
 internal void SetBarWidth(double width)
 {
     if (this.BarWidth.IsNaN() ||
         DependencyPropertyHelper.GetValueSource(this, BarWidthProperty).IsCurrent)
     {
         SetCurrentValue(BarWidthProperty, width);
     }
 }
 private void RestoreSeparatorVisibility(AppBarSeparator separator)
 {
     if (separator.Visibility == Visibility.Collapsed &&
         DependencyPropertyHelper.GetValueSource(separator, VisibilityProperty).IsCurrent)
     {
         separator.InvalidateProperty(VisibilityProperty);
     }
 }
示例#30
0
 /// <summary>Sets the value of the <paramref name="property"/> only if it hasn't been explicitly set.</summary>
 public static bool SetIfDefault <T>(this DependencyObject o, DependencyProperty property, T value)
 {
     if (DependencyPropertyHelper.GetValueSource(o, property).BaseValueSource == BaseValueSource.Default)
     {
         o.SetValue(property, value);
         return(true);
     }
     return(false);
 }