protected virtual void OnAssociatedObjectLoaded()
        {
            var frameworkElement = ((FrameworkElement) AssociatedObject);
            frameworkElement.DataContextChanged += OnDataContextChanged;

            _expression = GetBindingExpressionToValidate(frameworkElement);
            _viewModel = frameworkElement.DataContext as INotifyPropertyChanged;

            var triggerValidate = (ITriggerValidate) _viewModel;
            if (triggerValidate != null)
            {
                _canValidate = triggerValidate.CanValidate;
                triggerValidate.CanValidateChanged += () =>
                {
                    _canValidate = triggerValidate.CanValidate;
                    Refresh();
                };
            }
            else
            {
                throw new InvalidOperationException("The view model must implement the ITriggerValidate interface");
            }

            HookPropertyChangedAndRefresh();
        }
Пример #2
0
        public static Action Bind(this UISwitch toggle, INotifyPropertyChanged source, string propertyName)
        {
            var property = source.GetProperty(propertyName);

            if (property.PropertyType == typeof(bool))
            {
                toggle.SetValue(source, property);
                var handler = new PropertyChangedEventHandler ((s, e) =>
                {
                    if (e.PropertyName == propertyName)
                    {
                            toggle.InvokeOnMainThread(()=>
                                toggle.SetValue(source, property));
                    }
                });

                source.PropertyChanged += handler;

                var valueChanged = new EventHandler(
                    (sender, e) => property.GetSetMethod().Invoke (source, new object[]{ toggle.On }));

                toggle.ValueChanged += valueChanged;

                return new Action(() =>
                {
                    source.PropertyChanged -= handler;
                    toggle.ValueChanged -= valueChanged;
                });
            } 
            else
            {
                throw new InvalidCastException ("Binding property is not boolean");
            }
        }
Пример #3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="DependencyObserver"/> class.
		/// </summary>
		/// <param name="messageHandler">The message handler.</param>
		/// <param name="methodFactory">The method factory.</param>
		/// <param name="notifier">The notifier.</param>
		public DependencyObserver(IRoutedMessageHandler messageHandler, IMethodFactory methodFactory, INotifyPropertyChanged notifier)
		{
			_messageHandler = messageHandler;
			_methodFactory = methodFactory;
			_notifier = notifier;
			_singlePathObservers = new Dictionary<string, SinglePropertyPathObserver>();
		}
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DependencyObserver"/> class.
 /// </summary>
 /// <param name="messageHandler">The message handler.</param>
 /// <param name="methodFactory">The method factory.</param>
 /// <param name="notifier">The notifier.</param>
 public DependencyObserver(IRoutedMessageHandler messageHandler, IMethodFactory methodFactory, INotifyPropertyChanged notifier)
 {
     _messageHandler = messageHandler;
     _methodFactory = methodFactory;
     _weakNotifier = new WeakReference<INotifyPropertyChanged>(notifier);
     _monitoringInfos = new Dictionary<string, MonitoringInfo>();
 }
Пример #5
0
        private static void RemoveHandler(INotifyPropertyChanged dataContext)
        {
            if (dataContext == null || !Handlers.ContainsKey(dataContext)) return;

            dataContext.PropertyChanged -= Handlers[dataContext].PropertyChanged;
            Handlers.Remove(dataContext);
        }
Пример #6
0
 protected override void OnCreate(Bundle bundle)
 {
     base.OnCreate(bundle);
     SetContentView(Resource.Layout.FirstPrinciplesView);
     _dataContext = new SimpleViewModel();
     ApplyBindings();
 }
Пример #7
0
 private void StartWatching(INotifyPropertyChanged npc)
 {
     if (npc == null) throw new ArgumentNullException("npc");
     PropertyChangedEventManager.AddListener(npc,
         new WeakEventListener((t, o, arg) => Console.WriteLine("PropertyChanged event: Type: {0}, Sender: {1}, EventArgs: {2}",t,o,arg)),
         string.Empty);
 }
Пример #8
0
        public DependencyManager(INotifyPropertyChanged instance, PropertyChangedEventHandler propertyChangedEventHandler)
        {
            Instance = instance;
            PropertyChangedEventHandler = propertyChangedEventHandler;

            Initialize();
        }
 /// <summary>
 /// Asserts that property changed is not called for the specified property when the value of the property is set
 /// to the specified value.
 /// </summary>
 /// <param name="observableObject">The object that will be observed.</param>
 /// <param name="propertyName">The name of the property that will be observed.</param>
 /// <param name="value">The value to which the property should be set.</param>
 public static void PropertyChangedIsNotCalled(
     INotifyPropertyChanged observableObject,
     string propertyName,
     object value)
 {
     PropertyChangedIsCalled(observableObject, propertyName, value, false);
 }
 /// <summary>
 ///     Includes the INotifyPropertyChanged.
 /// </summary>
 /// <param name="changed">INotifyPropertyChanged.</param>
 public void Include(INotifyPropertyChanged changed)
 {
     changed.PropertyChanged += (sender, e) =>
     {
         var test = e.PropertyName;
     };
 }
Пример #11
0
 public SourceBindingEndpoint(INotifyPropertyChanged source, Type propertyType, dynamic propertyGetter, Delegate propertySetter)
 {
     this.Source = source;
     this.PropertyType = propertyType;
     this.PropertyGetter = propertyGetter;
     this.PropertySetter = propertySetter;
 }
 public BindingContext(
     INotifyPropertyChanged propertyMotherToWatch, 
     Func<PropertyChangedEventHandler> propertyEventProvider)
 {
     _PropertyMother = propertyMotherToWatch;
     _PropertyEventProvider = propertyEventProvider;
 }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FireOnPropertyChanged"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 public FireOnPropertyChanged(INotifyPropertyChanged parent)
 {
     Parent = parent;
     Parent.PropertyChanged += OnPropertyChanged;
     EventStore = new Dictionary<string, PropertyChangedEventHandler>();
 
 }
Пример #14
0
        /// <summary>
        /// Add a handler for the given source's event.
        /// </summary>
        public static void AddHandler(INotifyPropertyChanged source, EventHandler<PropertyChangedEventArgs> handler, string propertyName)
        {
            if (handler == null)
                throw new ArgumentNullException("handler");

            CurrentManager.PrivateAddHandler(source, handler, propertyName);
        }
Пример #15
0
 public PropertyChangedEventListener(INotifyPropertyChanged source, PropertyChangedEventHandler handler)
 {
     if (source == null) { throw new ArgumentNullException("source"); }
     if (handler == null) { throw new ArgumentNullException("handler"); }
     this.source = source;
     this.handler = handler;
 }
Пример #16
0
        internal SubscriptionTree(INotifyPropertyChanged parameter, List<SubscriptionNode> children)
        {
            this.Parameter = parameter;
            this.Children = children;

            SubscribeToEntireTree(this.Children);
        }
Пример #17
0
        /// <summary>
        /// Verifies that the provided object raised INotifyPropertyChanged.PropertyChanged
        /// as a result of executing the given test code.
        /// </summary>
        /// <param name="object">The object which should raise the notification</param>
        /// <param name="propertyName">The property name for which the notification should be raised</param>
        /// <param name="testCode">The test code which should cause the notification to be raised</param>
        /// <exception cref="PropertyChangedException">Thrown when the notification is not raised</exception>
        public static void PropertyChanged(INotifyPropertyChanged @object, string propertyName, Action testCode)
        {
            Guard.ArgumentNotNull("object", @object);
            Guard.ArgumentNotNull("testCode", testCode);

            bool propertyChangeHappened = false;

            PropertyChangedEventHandler handler = (sender, args) =>
            {
                if (propertyName.Equals(args.PropertyName, StringComparison.OrdinalIgnoreCase))
                    propertyChangeHappened = true;
            };

            @object.PropertyChanged += handler;

            try
            {
                testCode();
                if (!propertyChangeHappened)
                    throw new PropertyChangedException(propertyName);
            }
            finally
            {
                @object.PropertyChanged -= handler;
            }
        }
 public TestNotifyPropertyChanged(INotifyPropertyChanged model,
                                  string expectedPropertyName = null)
 {
     m_Model = model;
     m_Model.PropertyChanged += OnPropertyChanged;
     m_ExpectedPropertyName = expectedPropertyName;
 }
Пример #19
0
        public PropertyBoundCommand(CommandExecute execute, INotifyPropertyChanged boundTo, string propertyName)
        {
            if (execute == null)
                throw new ArgumentNullException("execute");
            this.execute = execute;

            if (boundTo == null)
                throw new ArgumentNullException("boundTo");
            this.boundTo = boundTo;

            property = boundTo.GetType().GetProperty(propertyName);
            if (property == null)
                throw new ArgumentException("Bad propertyName");

            if (property.PropertyType != typeof(bool))
                throw new ArgumentException("Bad property type");

            propertyGetMethod = property.GetGetMethod();
            if (propertyGetMethod == null)
                throw new ArgumentException("No public get-method found.");

            this.propertyName = propertyName;

            boundTo.PropertyChanged += new PropertyChangedEventHandler(boundTo_PropertyChanged);
        }
Пример #20
0
        /// <summary>
        /// Clears the property binding.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="sourceProp">The source prop.</param>
        /// <param name="targetProp">The target prop.</param>
        public static void ClearPropertyBinding(Object source, INotifyPropertyChanged target, string sourceProp, string targetProp)
        {
            WeakEntry entry = new WeakEntry(source.GetType(), target.GetType(), sourceProp, targetProp);
            Delegate setAction = GetExpressionAction(entry, source, true);

            WeakSource.UnRegister(source, setAction, targetProp);
        }
Пример #21
0
        public static PropertyChangedEventHandler Bind(this SeekBar seekBar, INotifyPropertyChanged source, string propertyName)
        {
            var property = source.GetProperty(propertyName);

            var r = property.GetCustomAttribute<RangeAttribute> ();

            if (r != null)
            {
                seekBar.Max = (int)r.Maximum;
            }

            var handler = new PropertyChangedEventHandler ((s, e) =>
                {
                    if (e.PropertyName == propertyName)
                    {
                        //textField.SetText(source, property);
                    }
                });

            source.PropertyChanged += handler;

            //textField.AfterTextChanged += (sender, e) => property.GetSetMethod().Invoke(source, new []{textField.Text});

            return handler;
        }
Пример #22
0
        /// <summary>
        /// Creates a custom binding for the <see cref="TextView"/>.
        /// Remember to call <see cref="IMvxViewBindingManager.UnbindView"/> on the view after you're done
        /// using it.
        /// </summary>
        public static void BindToText(this TextView view, INotifyPropertyChanged source,
                                      string sourcePropertyName, IMvxValueConverter converter = null,
                                      object converterParameter = null)
        {
            var activity = view.Context as IMvxBindingActivity;
            if (activity == null)
                return;

            var description = new MvxBindingDescription
            {
                SourcePropertyPath = sourcePropertyName,
                Converter = converter,
                ConverterParameter = converterParameter,
                TargetName = "Text",
                Mode = MvxBindingMode.OneWay
            }.ToEnumerable();

            var tag = view.GetBindingTag ();
            if (tag != null) {
                MvxBindingTrace.Trace(
                    MvxTraceLevel.Warning,
                    "Replacing binding tag for a TextView " + view.Id);
            }

            view.SetBindingTag (new MvxViewBindingTag (description));
            activity.BindingManager.BindView (view, source);
        }
        public DependentRelayCommand(Action execute, Func<bool> canExecute,
                                     INotifyPropertyChanged target,
                                     params Expression<Func<object>>[] dependentPropertyExpressions)
            : base(execute, canExecute)
        {
            _dependentPropertyNames = new List<string>();
            foreach (var body in dependentPropertyExpressions.Select(expression => expression.Body))
            {
                var expression = body as MemberExpression;
                if (expression != null)
                {
                    _dependentPropertyNames.Add(expression.Member.Name);
                }
                else
                {
                    var unaryExpression = body as UnaryExpression;
                    if (unaryExpression != null)
                    {
                        _dependentPropertyNames.Add(((MemberExpression)unaryExpression.Operand).Member.Name);
                    }
                }
            }

            target.PropertyChanged += TargetPropertyChanged;
        }
 public MvxNamedNotifyPropertyChangedEventSubscription(INotifyPropertyChanged source,
                                                       string propertyName,
                                                       EventHandler<PropertyChangedEventArgs> targetEventHandler)
     : base(source, targetEventHandler)
 {
     _propertyName = propertyName;
 }
        /// <summary>
        /// Locates the dialog type representing the specified view model in a user interface.
        /// </summary>
        /// <param name="viewModel">The view model to find the dialog type for.</param>
        /// <returns>
        /// The dialog type representing the specified view model in a user interface.
        /// </returns>
        internal static Type LocateDialogType(INotifyPropertyChanged viewModel)
        {
            if (viewModel == null)
                throw new ArgumentNullException("viewModel");

            Type viewModelType = viewModel.GetType();

            Type dialogType = Cache.Get(viewModelType);
            if (dialogType != null)
            {
                return dialogType;
            }

            string dialogName = GetDialogName(viewModelType);
            string dialogAssemblyName = GetAssemblyFullName(viewModelType);

            string dialogFullName = "{0}, {1}".InvariantFormat(
                dialogName,
                dialogAssemblyName);
            
            dialogType = Type.GetType(dialogFullName);
            if (dialogType == null)
                throw new Exception(Resources.DialogTypeMissing.CurrentFormat(dialogFullName));

            Cache.Add(viewModelType, dialogType);
            
            return dialogType;
        }
Пример #26
0
 // Action is required. CanExecute defaults to true. Parent is optional
 public CommandHook(Action<object> action, Func<object, bool> canExecute, INotifyPropertyChanged parent)
 {
     this.canExecute = canExecute;
     this.action = action;
     if (parent != null)
         parent.PropertyChanged += Parent_PropertyChanged;
 }
Пример #27
0
        public static void RemoveListener(INotifyPropertyChanged source, IWeakEventListener listener)
        {
            if (source == null) { throw new ArgumentNullException("source"); }
            if (listener == null) { throw new ArgumentNullException("listener"); }

            PropertyChangedEventManager.CurrentManager.ProtectedRemoveListener(source, listener);
        }
        /// <summary>
        /// Asserts that property changed is called for the specified property when the value of the property is set
        /// to the specified value.
        /// </summary>
        /// <param name="observableObject">The object that will be observed.</param>
        /// <param name="propertyName">The name of the property that will be observed.</param>
        /// <param name="value">The value to which the property should be set.</param>
        /// <param name="isRaised">Determines wether property changed should be called or not.</param>
        private static void PropertyChangedIsCalled(
            INotifyPropertyChanged observableObject,
            string propertyName,
            object value,
            bool isRaised)
        {
            var propertyFound = false;
            var propertyChangedCalled = false;
            observableObject.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == propertyName)
                {
                    propertyChangedCalled = true;
                }
            };

            var properties = observableObject.GetType().GetProperties();

            foreach (var propertyInfo in properties)
            {
                if (propertyInfo.Name == propertyName)
                {
                    propertyInfo.SetValue(observableObject, value, null);
                    propertyFound = true;
                    break;
                }
            }

            Assert.IsTrue(
                propertyFound,
                string.Format("The property {0} could not be found on object {1}.", propertyName, observableObject));

            Assert.AreEqual(isRaised, propertyChangedCalled);
        }
Пример #29
0
		public WeakINPCListener (INotifyPropertyChanged source, IListenINPC listener)
		{
			Source = source;
			Listener = listener;

			Source.PropertyChanged += HandleSourcePropertyChanged;
		}
Пример #30
0
 public ValidationTemplate(INotifyPropertyChanged target)
 {
     this.target = target;
     validator = GetValidator(target.GetType());
     validationResult = validator.Validate(target);
     target.PropertyChanged += Validate;
 }
 public static MvxNamedNotifyPropertyChangedEventSubscription <T> WeakSubscribe <T>(this INotifyPropertyChanged source,
                                                                                    Expression <Func <T> > property,
                                                                                    EventHandler <PropertyChangedEventArgs>
                                                                                    eventHandler)
 {
     return(new MvxNamedNotifyPropertyChangedEventSubscription <T>(source, property, eventHandler));
 }
 public static MvxNotifyPropertyChangedEventSubscription WeakSubscribe(this INotifyPropertyChanged source,
                                                                       EventHandler <PropertyChangedEventArgs>
                                                                       eventHandler)
 {
     return(new MvxNotifyPropertyChangedEventSubscription(source, eventHandler));
 }
Пример #33
0
 public PlotterBase CreatePlotter(INotifyPropertyChanged viewModel)
 {
     return(new PngPlotter((PngPlotterViewModel)viewModel));
 }
Пример #34
0
 public void Include(INotifyPropertyChanged changed)
 {
     changed.PropertyChanged += (sender, e) => { _ = e.PropertyName; };
 }
Пример #35
0
        // ObservePropertyChanged ================================

        /// <example><code>
        /// model
        ///     .ObservePropertyChanged()
        ///     .Subscribe(e => Console.WriteLine($"SomePropertyChangedEvent occurred."));
        /// </code></example>
        public static IObservable <EventPattern <PropertyChangedEventArgs> > ObservePropertyChanged(this INotifyPropertyChanged source)
        {
            return(source.ObserveEvent <PropertyChangedEventArgs>(nameof(source.PropertyChanged)));
        }
Пример #36
0
 /// <summary>
 /// Bind properties of two objects bidirectionally, converting the values using a converter.
 /// Synchronization can be intercepted by adding a validator.
 /// </summary>
 /// <param name="controlObject">Object containing 1st property to bind</param>
 /// <param name="controlPropertyName">Property of 1st object to bind</param>
 /// <param name="fieldObject">Object containing 2nd property to bind</param>
 /// <param name="fieldPropertyName">Property of 2nd object to bind</param>
 /// <param name="validator">validator to intercept synchronization if the value does not match certain criteria</param>
 public BidirectionalBinding(INotifyPropertyChanged controlObject, string controlPropertyName, INotifyPropertyChanged fieldObject, string fieldPropertyName, IBindingValidator validator) : this(controlObject, controlPropertyName, fieldObject, fieldPropertyName)
 {
     this.validator = validator;
 }
Пример #37
0
 public WeakPropertyChangedProxy(INotifyPropertyChanged source, PropertyChangedEventHandler listener) : this()
 {
     SubscribeTo(source, listener);
 }
 private void SaveConfig(INotifyPropertyChanged config)
 {
     Svc.Configuration.Save <ImportGlobalCfg>(GlobalConfig).RunAsync();
 }
 /// <summary>
 /// Initializes a new instance of the BindableValidator class with the entity to validate.
 /// </summary>
 /// <param name="entityToValidate">The entity to validate</param>
 /// <param name="getResourceDelegate">A delegate that returns a string resource given a resource map Id and resource Id</param>
 /// <exception cref="ArgumentNullException">When <paramref name="entityToValidate"/> is <see langword="null" />.</exception>
 public BindableValidator(INotifyPropertyChanged entityToValidate, Func <string, string, string> getResourceDelegate)
     : this(entityToValidate)
 {
     _getResourceDelegate = getResourceDelegate;
 }
Пример #40
0
 public static IObservable <PropertyChangedEventArgs> ObservePropertyChanged(this INotifyPropertyChanged source)
 {
     return(Observable.FromEventPattern <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                h => source.PropertyChanged += h, h => source.PropertyChanged -= h)
            .Select(x => x.EventArgs));
 }
Пример #41
0
        /// <summary>
        /// Bind properties of two objects bidirectionally
        /// </summary>
        /// <param name="object1">Object containing 1st property to bind</param>
        /// <param name="property1">Property of 1st object to bind</param>
        /// <param name="object2">Object containing 2nd property to bind</param>
        /// <param name="property2">Property of 2nd object to bind</param>
        public BidirectionalBinding(INotifyPropertyChanged controlObject, string controlPropertyName, INotifyPropertyChanged fieldObject, string fieldPropertyName)
        {
            this.controlObject       = controlObject;
            this.fieldObject         = fieldObject;
            this.controlPropertyName = controlPropertyName;
            this.fieldPropertyName   = fieldPropertyName;

            this.controlObject.PropertyChanged += ControlPropertyChanged;
            this.fieldObject.PropertyChanged   += FieldPropertyChanged;
        }
Пример #42
0
 /// <summary>
 /// Bind properties of two objects bidirectionally, converting the values using a converter
 /// </summary>
 /// <param name="controlObject">Object containing 1st property to bind</param>
 /// <param name="controlPropertyName">Property of 1st object to bind</param>
 /// <param name="fieldObject">Object containing 2nd property to bind</param>
 /// <param name="fieldPropertyName">Property of 2nd object to bind</param>
 /// <param name="converter">taking care of converting the synchronized value to the correct target format and back</param>
 public BidirectionalBinding(INotifyPropertyChanged controlObject, string controlPropertyName, INotifyPropertyChanged fieldObject, string fieldPropertyName, IBindingConverter converter) : this(controlObject, controlPropertyName, fieldObject, fieldPropertyName)
 {
     this.converter = converter;
 }
 public PropertyChangedEventListener(INotifyPropertyChanged source, PropertyChangedEventHandler handler)
 {
     Source  = source;
     Handler = handler;
     Source.PropertyChanged += Handler;
 }
Пример #44
0
        private void synchronize(INotifyPropertyChanged sourceObject, string sourceProperty, INotifyPropertyChanged targetObject, string targetProperty)
        {
            PropertyInfo targetPropertyInfo = resolvePropertyInfo(targetObject, targetProperty);
            PropertyInfo sourcePropertyInfo = resolvePropertyInfo(sourceObject, sourceProperty);

            if (sourcePropertyInfo != null && targetPropertyInfo != null && targetPropertyInfo.CanWrite)
            {
                object bValue = sourcePropertyInfo.GetValue(sourceObject, null);
                if (converter != null && bValue != null)
                {
                    bValue = converter.convert(bValue);
                }
                try
                {
                    if (validator == null || validator.validate(bValue))
                    {
                        targetPropertyInfo.SetValue(targetObject, bValue, null);
                    }
                }
                catch (Exception e)
                {
                    throw new MemberAccessException("Could not set property '" + targetProperty + "' to '" + bValue + "' [" + ((bValue != null) ? bValue.GetType().Name : "") + "] on " + targetObject + ". Probably other type than expected, IBindingCoverter to the rescue.", e);
                }
            }
        }
Пример #45
0
 public static ChangeListener Create(INotifyPropertyChanged value)
 {
     return(Create(value, null));
 }
Пример #46
0
 public void AddSource(INotifyPropertyChanged obj)
 {
     obj.PropertyChanged += OnSourceChanged;
     Dependencies         = Dependencies.Concat(new WeakReference <INotifyPropertyChanged>[] { new WeakReference <INotifyPropertyChanged>(obj) });
     Fire();
 }
 public ChildChangeListener(INotifyPropertyChanged instance, string propertyName)
     : this(instance)
 {
     PropertyName = propertyName;
 }
Пример #48
0
 public INPCPropertyObservation(INotifyPropertyChanged notifyObject, string propertyName)
 {
     _propertyName = propertyName;
     notifyObject.PropertyChanged += notifyObject_PropertyChanged;
 }
Пример #49
0
 /// <summary>
 /// Creates a special binding for the <see cref="INotifyPropertyChanged.PropertyChanged"/> event of the specified <paramref name="source"/>, which allows to update the
 /// specified <paramref name="targetPropertyName"/> in the <paramref name="targets"/>, when the property of <paramref name="sourcePropertyName"/> changes in the <paramref name="source"/>.
 /// </summary>
 /// <param name="source">The source object, whose property specified by the <paramref name="sourcePropertyName"/> parameter is observed.</param>
 /// <param name="sourcePropertyName">The name of the property, whose change is observed.</param>
 /// <param name="targetPropertyName">The name of the property in the target object(s).</param>
 /// <param name="format">If not <see langword="null"/>, then can be used to format the value to be set in the <paramref name="targets"/>.</param>
 /// <param name="targets">The targets to be updated. If the concrete instances to update have to be returned when the change occurs use the <see cref="ICommandBinding.AddTarget(Func{object})">ICommandBinding.AddTarget</see>
 /// method on the result <see cref="ICommandBinding"/> instance.</param>
 /// <returns>An <see cref="ICommandBinding"/> instance, to which the specified <paramref name="source"/> and <paramref name="targets"/> are bound.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="source"/>, <paramref name="sourcePropertyName"/> or <paramref name="targetPropertyName"/> is <see langword="null"/>.</exception>
 /// <remarks>
 /// <para>This method uses a prepared command internally, which is bound to the <see cref="INotifyPropertyChanged.PropertyChanged"/> event of the specified <paramref name="source"/> object.</para>
 /// <para>The <see cref="ICommandState"/>, which is created for the underlying command contains the specified property names and <paramref name="format"/>parameters.
 /// Do not remove these state entries; otherwise, the command will throw an <see cref="InvalidOperationException"/> when executed.</para>
 /// <para>The property with <paramref name="targetPropertyName"/> will be set in the specified <paramref name="targets"/> immediately when this method is called.
 /// The targets, which are added later by the <see cref="O:KGySoft.ComponentModel.ICommandBinding.AddTarget">ICommandBinding.AddTarget</see> methods, are set only when the
 /// <see cref="INotifyPropertyChanged.PropertyChanged"/> event occurs on the <paramref name="source"/> object.</para>
 /// </remarks>
 public static ICommandBinding CreatePropertyBinding(this INotifyPropertyChanged source, string sourcePropertyName, string targetPropertyName, Func <object, object> format, params object[] targets)
 => CreatePropertyBinding((object)source, sourcePropertyName, targetPropertyName, format, targets);
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="container">The container.</param>
 /// <param name="propertyName">The property name.</param>
 /// <param name="description">THe property description.</param>
 public EnumValueNudger(INotifyPropertyChanged container, string propertyName, string description)
     : base(container, propertyName, description)
 {
     _enumValues = Enum.GetValues(Property.PropertyType);
 }
        /// <summary>
        /// Given a collection, index and item to remove, will try to remove that item
        /// from the index. If the item has duplicates, will verify that only the first
        /// instance was removed.
        /// </summary>
        public void RemoveItemTest(ReadOnlyObservableCollection <string> readOnlyCol, ObservableCollection <string> collection,
                                   int itemIndex, string itemToRemove, bool isSuccessfulRemove, bool hasDuplicates)
        {
            INotifyPropertyChanged readOnlyPropertyChanged = readOnlyCol;

            readOnlyPropertyChanged.PropertyChanged += Collection_PropertyChanged;
            _expectedPropertyChanged = new[]
            {
                new PropertyNameExpected(COUNT),
                new PropertyNameExpected(ITEMARRAY)
            };

            INotifyCollectionChanged readOnlyCollectionChange = readOnlyCol;

            readOnlyCollectionChange.CollectionChanged += Collection_CollectionChanged;

            if (isSuccessfulRemove)
            {
                _expectedCollectionChangedFired++;
            }

            _expectedAction           = NotifyCollectionChangedAction.Remove;
            _expectedNewItems         = null;
            _expectedNewStartingIndex = -1;
            _expectedOldItems         = new string[] { itemToRemove };
            _expectedOldStartingIndex = itemIndex;

            int expectedCount = isSuccessfulRemove ? collection.Count - 1 : collection.Count;

            bool removedItem = collection.Remove(itemToRemove);

            Assert.Equal(expectedCount, readOnlyCol.Count);
            Assert.Equal(_expectedCollectionChangedFired, _numCollectionChangedFired);

            if (isSuccessfulRemove)
            {
                foreach (var item in _expectedPropertyChanged)
                {
                    Assert.True(item.IsFound, "The propertychanged event should have fired for" + item.Name + ", since an item was removed");
                }

                Assert.True(removedItem, "Should have been successful in removing the item.");
            }
            else
            {
                foreach (var item in _expectedPropertyChanged)
                {
                    Assert.False(item.IsFound, "The propertychanged event should have fired for" + item.Name + ", since no items were removed.");
                }

                Assert.False(removedItem, "Should not have been successful in removing the item.");
            }
            if (hasDuplicates)
            {
                return;
            }

            // ensuring that the item is not in the collection.
            for (int i = 0; i < readOnlyCol.Count; i++)
            {
                if (itemToRemove == readOnlyCol[i])
                {
                    string itemsInCollection = "";
                    foreach (var item in readOnlyCol)
                    {
                        itemsInCollection += item + ", ";
                    }

                    Assert.True(false, "Found item (" + itemToRemove + ") that should not be in the collection because we tried to remove it. Collection: " + itemsInCollection);
                }
            }

            readOnlyCollectionChange.CollectionChanged -= Collection_CollectionChanged;
            readOnlyPropertyChanged.PropertyChanged    -= Collection_PropertyChanged;
        }
Пример #52
0
 /// <summary>
 /// INotifyPropertyChanged implementating class.
 /// </summary>
 /// <param name="Sender"></param>
 public INPCInvoker(INotifyPropertyChanged Sender)
 {
     _Sender = Sender;
 }
Пример #53
0
 public void SetProtectedField(INotifyPropertyChanged value)
 {
     ProtectedField = value;
 }
Пример #54
0
 /// <summary>
 /// Detaches the event source.
 /// </summary>
 /// <param name="item">The item to detach.</param>
 protected void DetachEventSource([NotNull] INotifyPropertyChanged item)
 {
     Contract.Requires(item != null);
     item.PropertyChanged -= RelaySource_PropertyChanged;
     EventSources.Remove(item.GetType());
 }
Пример #55
0
 public void OnObject(INotifyPropertyChanged listenedObject)
 {
     _OnObject(listenedObject);
 }
Пример #56
0
 public void SetPrivateField(INotifyPropertyChanged value)
 {
     privateField = value;
 }
 /// <summary>
 /// Raises the property changed event in the mock object
 /// </summary>
 /// <param name="mock">Mock instance to use</param>
 /// <param name="propertyName">Property name to use in the event</param>
 public static void RaisePropertyChanged(this INotifyPropertyChanged mock, string propertyName)
 {
     mock.Raise(mo => mo.PropertyChanged += null, mock, new PropertyChangedEventArgs(propertyName));
 }
 private ExpectChanges ExpectChanges(INotifyPropertyChanged source, params string[] expected) =>
 new ExpectChanges(source, expected);
Пример #59
0
 internal static void SetBinding(this MockUIView target, string targetProperty, BindingBase binding, INotifyPropertyChanged propertyChanged)
 {
     NativeBindingHelpers.SetBinding(target, targetProperty, binding, propertyChanged);
 }
Пример #60
0
        public bool SetPropertyValueOfElement(string elementName,
                                              string property,
                                              object value)
        {
            Debug.Assert(!string.IsNullOrEmpty(property));

            if (null == m_curHtmlDocument)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(elementName))
            {
                switch (property)
                {
                case UIPropertyKey.s_DataContextKey:
                {
                    if (null != m_dataContext &&
                        m_dataContext is INotifyPropertyChanged)
                    {
                        INotifyPropertyChanged iNotify = m_dataContext as INotifyPropertyChanged;
                        Debug.Assert(null != iNotify);
                        iNotify.PropertyChanged -= OnDataPropertyChanged;
                    }

                    m_dataContext = value;
                    if (null != m_dataContext &&
                        m_dataContext is INotifyPropertyChanged)
                    {
                        INotifyPropertyChanged iNotify = m_dataContext as INotifyPropertyChanged;
                        Debug.Assert(null != iNotify);
                        iNotify.PropertyChanged += OnDataPropertyChanged;
                    }

                    //lock ( m_synElementLock )
                    {
                        foreach (var screenElement in m_dicScreenElements)
                        {
                            screenElement.Value.SetBindingTarget(m_dataContext);
                        }
                    }
                }
                break;

                default:
                {
                    return(false);
                }
                }
            }
            else if (elementName.Equals(SpecialElement.s_Focus, StringComparison.OrdinalIgnoreCase))
            {
                if (null != m_focusElement)
                {
                    m_focusElement.SetPropertyValue(property, value);
                }
            }
            else
            {
                elementName = elementName.ToLowerInvariant();
                if (m_dicScreenElements.ContainsKey(elementName))
                {
                    return(m_dicScreenElements[elementName].SetPropertyValue(property, value));
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }