Example #1
0
        private static void OnTargetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DescriptionViewer dv = d as DescriptionViewer;

            if (dv != null)
            {
                bool targetFocused = e.NewValue == FocusManager.GetFocusedElement();
                if (dv.IsFocused != targetFocused)
                {
                    dv.IsFocused = targetFocused;
                }
                dv.LoadMetadata(false);

                FrameworkElement oldElement = e.OldValue as FrameworkElement;
                FrameworkElement newElement = e.NewValue as FrameworkElement;
                EventHandler <ValidationErrorEventArgs> bindingHandler = new EventHandler <ValidationErrorEventArgs>(dv.Target_BindingValidationError);
                RoutedEventHandler gotFocusHandler  = new RoutedEventHandler(dv.Target_GotFocus);
                RoutedEventHandler lostFocusHandler = new RoutedEventHandler(dv.Target_LostFocus);
                if (oldElement != null)
                {
                    oldElement.BindingValidationError -= bindingHandler;
                    oldElement.GotFocus  -= gotFocusHandler;
                    oldElement.LostFocus -= lostFocusHandler;
                }
                if (newElement != null)
                {
                    newElement.BindingValidationError += bindingHandler;
                    newElement.GotFocus  += gotFocusHandler;
                    newElement.LostFocus += lostFocusHandler;
                }
                dv.ParseTargetValidState();
            }
        }
Example #2
0
        private static void OnPropertyPathPropertyChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)
        {
            DescriptionViewer dv = depObj as DescriptionViewer;

            if (dv != null && dv.Initialized)
            {
                dv.LoadMetadata(false);
                // Changing the PropertyPath sometimes requires an update for the validation state, since it might be stale.
                dv.ParseTargetValidState();
            }
        }
Example #3
0
        private static void OnDataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DescriptionViewer dv = d as DescriptionViewer;

            if (dv != null)
            {
                if (e.OldValue == null || e.NewValue == null || e.OldValue.GetType() != e.NewValue.GetType())
                {
                    // Refresh the metadata, but only if the DataContext's type has changed (or if either is null)
                    dv.LoadMetadata(false);
                }
            }
        }