当前位置: 首页>>代码示例>>C#>>正文


C# INotifyPropertyChanged类代码示例

本文整理汇总了C#中INotifyPropertyChanged的典型用法代码示例。如果您正苦于以下问题:C# INotifyPropertyChanged类的具体用法?C# INotifyPropertyChanged怎么用?C# INotifyPropertyChanged使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


INotifyPropertyChanged类属于命名空间,在下文中一共展示了INotifyPropertyChanged类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PropertyChangedIsCalled

        /// <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);
        }
开发者ID:MadCowDevelopment,项目名称:Channel9Downloader,代码行数:42,代码来源:Assertion.cs

示例2: BindingContext

 public BindingContext(
     INotifyPropertyChanged propertyMotherToWatch, 
     Func<PropertyChangedEventHandler> propertyEventProvider)
 {
     _PropertyMother = propertyMotherToWatch;
     _PropertyEventProvider = propertyEventProvider;
 }
开发者ID:jcbozonier,项目名称:master,代码行数:7,代码来源:BindingContext.cs

示例3: ValidationTemplate

 public ValidationTemplate(INotifyPropertyChanged target)
 {
     this.target = target;
     validator = GetValidator(target.GetType());
     validationResult = validator.Validate(target);
     target.PropertyChanged += Validate;
 }
开发者ID:Fody,项目名称:Validar,代码行数:7,代码来源:ValidationTemplate.cs

示例4: SubscriptionTree

        internal SubscriptionTree(INotifyPropertyChanged parameter, List<SubscriptionNode> children)
        {
            this.Parameter = parameter;
            this.Children = children;

            SubscribeToEntireTree(this.Children);
        }
开发者ID:ismell,项目名称:Continuous-LINQ,代码行数:7,代码来源:SubscriptionTree.cs

示例5: AddHandler

        /// <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);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:10,代码来源:PropertyChangedEventManager.cs

示例6: ClearPropertyBinding

        /// <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);
        }
开发者ID:kasicass,项目名称:kasicass,代码行数:14,代码来源:BindingEngine.cs

示例7: TestNotifyPropertyChanged

 public TestNotifyPropertyChanged(INotifyPropertyChanged model,
                                  string expectedPropertyName = null)
 {
     m_Model = model;
     m_Model.PropertyChanged += OnPropertyChanged;
     m_ExpectedPropertyName = expectedPropertyName;
 }
开发者ID:tschroedter,项目名称:Selkie.WPF,代码行数:7,代码来源:TestNotifyPropertyChanged.cs

示例8: OnAssociatedObjectLoaded

        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();
        }
开发者ID:MannusEtten,项目名称:uwp-validation,代码行数:25,代码来源:ValidationBehaviorBase.cs

示例9: StartWatching

 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);
 }
开发者ID:DamianReeves,项目名称:Stalker,代码行数:7,代码来源:IWatcher.cs

示例10: Bind

        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");
            }
        }
开发者ID:Qwin,项目名称:SimplyMobile,代码行数:34,代码来源:SwitchExtensions.cs

示例11: DependencyObserver

		/// <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>();
		}
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:13,代码来源:DependencyObserver.cs

示例12: DependencyObserver

 /// <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>();
 }
开发者ID:Mrding,项目名称:Ribbon,代码行数:13,代码来源:DependencyObserver.cs

示例13: RemoveHandler

        private static void RemoveHandler(INotifyPropertyChanged dataContext)
        {
            if (dataContext == null || !Handlers.ContainsKey(dataContext)) return;

            dataContext.PropertyChanged -= Handlers[dataContext].PropertyChanged;
            Handlers.Remove(dataContext);
        }
开发者ID:christophwille,项目名称:viennarealtime,代码行数:7,代码来源:BindableRuns.cs

示例14: BindToText

        /// <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);
        }
开发者ID:JoanMiro,项目名称:MvxMod,代码行数:32,代码来源:MvxTextSettingExtensions.cs

示例15: RemoveListener

        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);
        }
开发者ID:569550384,项目名称:Rafy,代码行数:7,代码来源:PropertyChangedEventManager.cs


注:本文中的INotifyPropertyChanged类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。