コード例 #1
0
        /// <summary>
        /// Detaches the listener.
        /// </summary>
        public void Detach()
        {
            if (RelayInstance == null)
                return;

            var temp = RelayInstance;
            RelayInstance = null;

            temp.ClearValue(RelayObject.ValueProperty);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of <see cref="DependencyPropertyChangedListener" />.
        /// </summary>
        /// <param name="sourceElement">The source element.</param>
        /// <param name="propertyPath">The property path.</param>
        /// <returns>The <see cref="DependencyPropertyChangedListener" />.</returns>
        /// <exception cref="System.ArgumentNullException">sourceElement</exception>
        /// <exception cref="System.ArgumentException">propertyPath is empty.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="sourceElement" /> parameter is null.</exception>
        /// <exception cref="ArgumentException">The <paramref name="propertyPath" /> is null or whitespace.</exception>
        public static DependencyPropertyChangedListener Create(DependencyObject sourceElement, string propertyPath)
        {
            if (sourceElement == null)
                throw new ArgumentNullException("sourceElement");

            if (string.IsNullOrWhiteSpace(propertyPath))
                throw new ArgumentException("propertyPath is empty.");

            var listener = new DependencyPropertyChangedListener();
            var binding = new Binding(propertyPath) { Source = sourceElement, Mode = BindingMode.OneWay };
            var relay = new RelayObject(listener);
            listener.RelayInstance = relay;

            BindingOperations.SetBinding(relay, RelayObject.ValueProperty, binding);

            return listener;
        }