1 // -------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 // -------------------------------------------------------------------
6 // - Removed class MouseCursor
8 //From \\authoring\Sparkle\Source\1.0.1083.0\Common\Source\Framework\ValueEditors
9 namespace System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.ValueEditors
12 using System.ComponentModel;
13 using System.Runtime.InteropServices;
15 using System.Windows.Data;
16 using System.Windows.Input;
17 using System.Windows.Interop;
18 using System.Windows.Media;
20 internal enum UpdateBindingType
26 internal static class ValueEditorUtils
28 // This property determines whether the commit keys (enter and escape) are marked handled by value editors or not. It inherits
29 // so can be set at any point in the tree, and all ValueEditors below that point in the UI will use this behavior.
30 public static readonly DependencyProperty HandlesCommitKeysProperty = DependencyProperty.RegisterAttached("HandlesCommitKeys", typeof(bool), typeof(ValueEditorUtils), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));
32 public static bool GetHandlesCommitKeys(DependencyObject dependencyObject)
34 return (bool)dependencyObject.GetValue(ValueEditorUtils.HandlesCommitKeysProperty);
37 public static void SetHandlesCommitKeys(DependencyObject dependencyObject, bool value)
39 dependencyObject.SetValue(ValueEditorUtils.HandlesCommitKeysProperty, value);
42 public static void UpdateBinding(FrameworkElement element, DependencyProperty property, bool updateSource)
44 ValueEditorUtils.UpdateBinding(element, property, (updateSource ? UpdateBindingType.Both : UpdateBindingType.Target));
47 public static void UpdateBinding(FrameworkElement element, DependencyProperty property, UpdateBindingType updateType)
49 BindingExpression bindingExpression = element.GetBindingExpression(property);
50 if (bindingExpression != null)
52 // If desired, push the current text value to the source of the binding.
53 if (updateType == UpdateBindingType.Source || updateType == UpdateBindingType.Both)
55 bindingExpression.UpdateSource();
58 // Update the text from the source of the binding.
59 if (updateType == UpdateBindingType.Target || updateType == UpdateBindingType.Both)
61 bindingExpression.UpdateTarget();
66 public static void ExecuteCommand(ICommand command, IInputElement element, object parameter)
68 RoutedCommand routedCommand = command as RoutedCommand;
69 if (routedCommand != null)
71 if (routedCommand.CanExecute(parameter, element))
73 routedCommand.Execute(parameter, element);
78 if (command != null && command.CanExecute(parameter))
80 command.Execute(parameter);