Beispiel #1
0
        public override void OnPropertyChanged(PropertyInfo propertyInfo, NotifyPropertyChanged sender)
        {
            var categoryNotifyPropertyChanged = sender as CategoryNotifyPropertyChanged;
            var category = categoryNotifyPropertyChanged != null ? categoryNotifyPropertyChanged.Category : null;

            OnPropertyChanged(new CategoryPropertyChangedEventArgs(propertyInfo.Name, category));
        }
Beispiel #2
0
        public bool Subscribe(NguiBaseBinding binding, NotifyPropertyChanged handler) {
            var context = binding.GetContext(Text);
            if (context == null) {
                return false;
            }

            var properties = new Dictionary<Type, Property>() {
                {typeof(bool), context.FindProperty<bool>(Text, binding)},
                {typeof(int), context.FindProperty<int>(Text, binding)},
                {typeof(float), context.FindProperty<float>(Text, binding)},
                {typeof(double), context.FindProperty<double>(Text, binding)}
            };
            var pair = properties.FirstOrDefault(x => x.Value != null);
            if (pair.Equals(default(KeyValuePair<Type, Property>))) {
                return false;
            }

            type = pair.Key;
            property = pair.Value;

            //Предотвращеие двойной подписи
            property.OnChange -= handler;
            property.OnChange += handler;

            return true;
        }
 public void CreateDependent_DependentsHasNoMemberReference()
 {
     var o = new NotifyPropertyChanged ();
     Func<int, string> f = a => a.ToString ();
     NotifyingProperty.CreateDependent (
             () => o.CurrentStep,
             () => null,
             () => f (42));
 }
Beispiel #4
0
        public void CreateDependent_DependentsHasNoMemberReference()
        {
            var o = new NotifyPropertyChanged();
            Func <int, string> f = a => a.ToString();

            NotifyingProperty.CreateDependent(
                () => o.CurrentStep,
                () => null,
                () => f(42));
        }
        public DataCoreInterceptor(Type dataCoreType, Type dtoType, NotifyPropertyChanged npc)
        {
            DataCoreType = dataCoreType;
            Type implType = dataCoreType.GetCustomAttribute <ImplementationAttribute>( )?.Type;

            ConstructorInfo ci = implType.GetConstructor(
                BindingFlags.Instance | BindingFlags.Public,
                null,
                new[] { typeof(Type), typeof(NotifyPropertyChanged) },
                null);

            DataCore = (IDataCore)ci.Invoke(new object[] { dtoType, npc });
        }
		public void NotifyPropertyChangedTest()
		{
			NotifyPropertyChanged changed = new NotifyPropertyChanged();

			changed.PropertyChanged += propertyChangeTest1;

			changed.Property1 = "Test22";

			changed.PropertyChanged -= propertyChangeTest1;

			bool methodCalled = false;

			changed.PropertyChanged += (sender, e) =>
				{
					methodCalled = true;
				};

			changed.Property2 = "prop2";

			Assert.IsTrue(methodCalled);

			changed = new NotifyPropertyChanged();

			methodCalled = false;

			changed.PropertyChanged += (sender, e) =>
				{
					methodCalled = true;
					Assert.AreEqual("Property3", e.PropertyName);
				};

			changed.Property3 = "prop3";

			Assert.IsTrue(methodCalled);

			changed = new NotifyPropertyChanged();

			methodCalled = false;

			changed.PropertyChanged += (sender, e) =>
				{
					methodCalled = true;
				};

			changed.Property4 = "prop4";

			Assert.IsTrue(methodCalled);
		}
Beispiel #7
0
        private string GetAuthName()
        {
            if (!(TargetObject is FrameworkElement framework))
            {
                return(null);
            }
            object                obj          = framework.DataContext;
            Type                  targetType   = obj.GetType();
            PropertyInfo          propertyInfo = targetType.GetProperty(Path.Path);
            string                authInfo     = propertyInfo.GetValue(obj)?.ToString();
            string                authName     = Converter.Convert(authInfo, typeof(string), ConverterParameter, ConverterCulture).ToString();
            NotifyPropertyChanged notifyObject = obj as NotifyPropertyChanged;

            notifyObject.PropertyChanged += NotifyObject_PropertyChanged;
            return(authName);
        }
Beispiel #8
0
        public DtoInterceptor(Type dtoType, IDataCore dataCore, NotifyPropertyChanged npc)
        {
            if (dataCore == null)
            {
                throw new ArgumentNullException(nameof(dataCore), $"{nameof( dataCore )} must not be null");
            }
            if (dtoType == null)
            {
                throw new ArgumentNullException(nameof(dtoType), $"{nameof( dtoType )} must not be null");
            }

            _dataCore = dataCore;
            DtoType   = dtoType;
            _npc      = npc;
            Init( );
        }
            public void Fact()
            {
                var ns = @"ComponentModel";
                var output = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName(), ns);
                var context = new EntitiesContext()
                {
                    Namespace = new Namespace(NAMESPACE, ns),
                    Imports = new[] {@"System.ComponentModel", @"DataTransferObjects" },
                    TypeName = new TypeName(@"", @"TB_MATE_SALE_PRICE", @"ViewModel"),
                    Inherits = @"TestViewModel",
                    Implements = new [] { @"INortifyPropertyChanged" },
                    OutputPath = output,
                };

                var viewmodel = new NotifyPropertyChanged(context);
                viewmodel.CreateViewModel(context.TypeName.ToString());

                TextTemplatingProcess.StartExplorer(context.OutputPath);
            }
Beispiel #10
0
 public NotifyPropertyChangedHelper(NotifyPropertyChanged notifyPropertyChanged)
 {
     _notifyPropertyChanged = notifyPropertyChanged;
 }
        /// <summary>
        /// Зарегистрировать зависимое свойство.
        /// </summary>
        /// <typeparam name="TProp">тип свойства</typeparam>
        /// <param name="expression">выражение, содержащее доступ к обёртке свойства для получения его имени</param>
        /// <param name="onPropertyChanged">обработчик события изменения свойства, или null, если не нужен</param>
        /// <param name="defaultValue">значение свойства по-умолчанию</param>
        /// <param name="onCoerce">обработчик, подправляющий значение свойства перед установкой, или null, если не нужен</param>
        /// <param name="onValidate">обработчик, проверяющий корректность значения свойства, или null, если не нужен</param>
        /// <returns>зарегистрированное зависимое свойство</returns>
        public static DependencyProperty Register <TProp>(Expression <Func <TSource, TProp> > expression, NotifyPropertyChanged <TSource, TProp> onPropertyChanged = null,
                                                          TProp defaultValue = default(TProp), Func <TSource, TProp, TProp> onCoerce = null, Func <TProp, bool> onValidate = null)
        {
            var propertyChangedCallback = onPropertyChanged != null ? (o, args) => onPropertyChanged((TSource)o, (TProp)args.OldValue, (TProp)args.NewValue) : (PropertyChangedCallback)null;
            var coerceValueCallback     = onCoerce != null ? (o, v) => onCoerce((TSource)o, (TProp)v) : (CoerceValueCallback)null;
            var validateValueCallback   = onValidate != null ? o => onValidate((TProp)o) : (ValidateValueCallback)null;

            return(DependencyProperty.Register(NameHelper <TSource> .Name(expression), typeof(TProp), typeof(TSource),
                                               new PropertyMetadata(defaultValue, propertyChangedCallback, coerceValueCallback),
                                               validateValueCallback));
        }
Beispiel #12
0
 public void Unsubscribe(NotifyPropertyChanged handler) {
     if (property == null) return;
     property.OnChange -= handler;
 }
Beispiel #13
0
 public override void OnPropertyChanged(PropertyInfo propertyInfo, NotifyPropertyChanged sender)
 {
     var categoryNotifyPropertyChanged = sender as CategoryNotifyPropertyChanged;
     var category = categoryNotifyPropertyChanged != null ? categoryNotifyPropertyChanged.Category : null;
     OnPropertyChanged(new CategoryPropertyChangedEventArgs(propertyInfo.Name, category));
 }
Beispiel #14
0
 public WeakEventDelegator(NotifyPropertyChanged target)
 {
     _eventTarget = target;
     _propertyMappings = new Dictionary<INotifyPropertyChanged, List<PropertyMapping>>();
 }
Beispiel #15
0
 public static IObservable <PropertyChangedEventArgs> WhenPropertyChanged(this NotifyPropertyChanged notifyPropertyChanged)
 {
     return(Observable.FromEvent <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                ev => notifyPropertyChanged.PropertyChanged += ev,
                ev => notifyPropertyChanged.PropertyChanged -= ev));
 }
Beispiel #16
0
 public NotifyPropertyChangedInterceptor(NotifyPropertyChanged npc)
 {
     _npc = npc;
 }