• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# INotifyPropertyChanged类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: PropertyBoundCommand

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


示例17: WeakINPCListener

		public WeakINPCListener (INotifyPropertyChanged source, IListenINPC listener)
		{
			Source = source;
			Listener = listener;

			Source.PropertyChanged += HandleSourcePropertyChanged;
		}
开发者ID:dfr0,项目名称:moon,代码行数:7,代码来源:WeakINPCListener.cs


示例18: PropertyChanged

        /// <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;
            }
        }
开发者ID:johnkg,项目名称:xunit,代码行数:34,代码来源:PropertyAsserts.cs


示例19: LocateDialogType

        /// <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;
        }
开发者ID:402214782,项目名称:mvvm-dialogs,代码行数:35,代码来源:NamingConventionDialogTypeLocator.cs


示例20: PropertyChangedEventListener

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# INuGenServiceProvider类代码示例发布时间:2022-05-24
下一篇:
C# INotifyCollectionChanged类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap