public static async Task <IProgressController> ShowProgressAsync(this INotifyPropertyChangedEx source, string title, string message, CancellationTokenSource cts = null, bool closeOnCancel = true)
        {
            var window         = App.Current.MainWindow as MetroWindow;
            var dialogSettings = GetDefaultDialogSettings();

            var controller = await window.ShowProgressAsync(title, message, cts != null, dialogSettings);

            var controllerProxy = new ProgressControllerProxy(controller);

            EventHandler cancelHandler = null;

            cancelHandler = delegate
            {
                controllerProxy.Canceled -= cancelHandler;
                try
                {
                    cts?.Cancel();
                }
                catch (ObjectDisposedException e) { }
                finally
                {
                    if (controllerProxy.IsOpen && closeOnCancel)
                    {
                        controllerProxy.CloseAsync();
                    }
                }
            };
            controllerProxy.Canceled += cancelHandler;

            return(controllerProxy);
        }
        public static async Task <YesNoAbortState> ConfirmWithCancelAsync(this INotifyPropertyChangedEx source, string title, string message, string yesText = null, string noText = null, string cancelText = null)
        {
            var window         = App.Current.MainWindow as MetroWindow;
            var dialogSettings = GetDefaultDialogSettings();

            dialogSettings.NegativeButtonText       = cancelText ?? "Abbruch";
            dialogSettings.AffirmativeButtonText    = yesText ?? "Ja";
            dialogSettings.FirstAuxiliaryButtonText = noText ?? "Nein";
            dialogSettings.DefaultButtonFocus       = MessageDialogResult.FirstAuxiliary;

            var result = await window.ShowMessageAsync(title, message, MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, dialogSettings).ConfigureAwait(false);

            switch (result)
            {
            case MessageDialogResult.Negative:
                return(YesNoAbortState.Abort);

            case MessageDialogResult.Affirmative:
                return(YesNoAbortState.Yes);

            case MessageDialogResult.FirstAuxiliary:
                return(YesNoAbortState.No);

            case MessageDialogResult.SecondAuxiliary:
                return(YesNoAbortState.No);
            }

            return(YesNoAbortState.Abort);
        }
        public ObservableProperty(TValue defaultValue, INotifyPropertyChangedEx notifier, string propertyName)
        {
            _current = defaultValue;
            _values  = new BehaviorSubject <TValue>(defaultValue);

            _notifySubscription = _values.DistinctUntilChanged().Do(value => _current = value).Subscribe(value => notifier.NotifyOfPropertyChange(propertyName));
        }
示例#4
0
 public static void Set <T>(this INotifyPropertyChangedEx viewModel, out T field, T value, [CallerMemberName] string propertyName = null)
 {
     field = value;
     if (propertyName != null)
     {
         viewModel.NotifyOfPropertyChange(propertyName);
     }
 }
        public static async Task ShowMessageAsync(this INotifyPropertyChangedEx source, string title, string message, string affirmativeText = null)
        {
            var window         = App.Current.MainWindow as MetroWindow;
            var dialogSettings = GetDefaultDialogSettings();

            dialogSettings.AffirmativeButtonText = affirmativeText ?? "Ok";

            await window.ShowMessageAsync(title, message, MessageDialogStyle.Affirmative, dialogSettings).ConfigureAwait(false);
        }
示例#6
0
        public static IDisposable ConnectINPCProperty <T>(this ObservableProperty <T> observableProperty,
                                                          INotifyPropertyChangedEx viewModel,
                                                          Expression <Func <T> > propertyExpression,
                                                          IDispatcherSchedulerProvider scheduler)
        {
            var propertyName = PropertyExtensions.ExtractPropertyName(propertyExpression);

            return(observableProperty.ValueChanged
                   .ObserveOn(scheduler.Dispatcher.RX)
                   .Subscribe(x => viewModel.ConnectINPC(propertyName)));
        }
示例#7
0
 public static bool SetValue <T>(this INotifyPropertyChangedEx viewModel, string propertyName, T value, ref T field)
 {
     if ((value == null && field != null) ||
         !value.Equals(field))
     {
         field = value;
         viewModel.NotifyOfPropertyChange(propertyName);
         return(true);
     }
     return(false);
 }
        public static async Task <bool> ConfirmAsync(this INotifyPropertyChangedEx source, string title, string message, string yesText = null, string noText = null)
        {
            var window         = App.Current.MainWindow as MetroWindow;
            var dialogSettings = GetDefaultDialogSettings();

            dialogSettings.NegativeButtonText    = noText ?? "Nein";
            dialogSettings.AffirmativeButtonText = yesText ?? "Ja";
            dialogSettings.DefaultButtonFocus    = MessageDialogResult.Affirmative;

            var result = await window.ShowMessageAsync(title, message, MessageDialogStyle.AffirmativeAndNegative, dialogSettings).ConfigureAwait(false);

            return(result == MessageDialogResult.Affirmative);
        }
示例#9
0
        private void SaveConfig(INotifyPropertyChangedEx config)
        {
            if (config.IsChanged)
            {
                config.IsChanged = false;

                if (config.GetType() == typeof(FeedsCfg))
                {
                    Svc.Configuration.Save(GlobalConfig, typeof(FeedsGlobalCfg)).RunAsync();
                }

                else
                {
                    Svc.Configuration.Save(config, config.GetType()).RunAsync();
                }
            }
        }
        public static bool Set <T>(this INotifyPropertyChangedEx propertyChanged, ref T field, T value, [CallerMemberName] string propertyName = null)
        {
            if (propertyChanged == null)
            {
                throw new ArgumentNullException(nameof(propertyChanged));
            }

            if (String.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            if (EqualityComparer <T> .Default.Equals(field, value))
            {
                return(false);
            }

            field = value;

            propertyChanged.NotifyOfPropertyChange(propertyName);

            return(true);
        }
示例#11
0
        public static bool Set <TProperty>(
            this INotifyPropertyChangedEx This,
            ref TProperty backingField,
            TProperty newValue,
            [CallerMemberName] string propertyName = null)
        {
            if (This == null)
            {
                throw new ArgumentNullException("This");
            }
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            if (EqualityComparer <TProperty> .Default.Equals(backingField, newValue))
            {
                return(false);
            }

            backingField = newValue;
            This.NotifyOfPropertyChange(propertyName);
            return(true);
        }
示例#12
0
        public void InitializeDependentProperties(INotifyPropertyChangedEx obj)
        {
            m_ClassInstancePropertyHost = obj;

            //m_DependentPropertyList.Clear();
            m_DependentPropsCache.Flush();

            foreach (var property in m_ClassInstancePropertyHost.GetType().GetProperties())
            {
                var attributeArray = (NotifyDependsOnAttribute[])
                                     property.GetCustomAttributes(typeof(NotifyDependsOnAttribute), false);

                foreach (var attribute in attributeArray)
                {
                    //m_DependentPropertyList.Add(new KeyValuePair<string, string>(attribute.DependsOn, property.Name));
#if DEBUG
                    VerifyPropertyName(attribute.DependsOn,
                                       (
                                           attribute.GetType() == typeof(NotifyDependsOnExAttribute)
                        ? ((NotifyDependsOnExAttribute)attribute).DependsOnType
                        : m_ClassInstancePropertyHost.GetType()
                                       )
                                       );
#endif
                    m_DependentPropsCache.Add(attribute.DependsOn, property.Name);
                }

                var attributeArrayFast = (NotifyDependsOnFastAttribute[])
                                         property.GetCustomAttributes(typeof(NotifyDependsOnFastAttribute), false);

                foreach (var attribute in attributeArrayFast)
                {
                    FieldInfo fi = m_ClassInstancePropertyHost.GetType().GetField(attribute.DependencyPropertyArgs, BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Static);
                    if (fi == null || fi.FieldType != typeof(PropertyChangedEventArgs))
                    {
                        Debug.Fail("Not a backing field for PropertyChangedEventArgs ?");
                        continue;
                    }
                    var dependencyPropertyArgs = fi.GetValue(null) as PropertyChangedEventArgs;
                    if (dependencyPropertyArgs == null)
                    {
                        Debug.Fail("Backing field for PropertyChangedEventArgs does not have a value ?");
                        continue;
                    }

                    fi = m_ClassInstancePropertyHost.GetType().GetField(attribute.DependentPropertyArgs, BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Static);
                    if (fi == null || fi.FieldType != typeof(PropertyChangedEventArgs))
                    {
                        Debug.Fail("Not a backing field for PropertyChangedEventArgs ?");
                        continue;
                    }
                    var dependentPropertyArgs = fi.GetValue(null) as PropertyChangedEventArgs;
                    if (dependentPropertyArgs == null)
                    {
                        Debug.Fail("Backing field for PropertyChangedEventArgs does not have a value ?");
                        continue;
                    }

                    //m_DependentPropertyList.Add(new KeyValuePair<string, string>(attribute.DependsOn, property.Name));
#if DEBUG
                    VerifyPropertyName(dependencyPropertyArgs.PropertyName, m_ClassInstancePropertyHost.GetType());
                    VerifyPropertyName(dependentPropertyArgs.PropertyName, m_ClassInstancePropertyHost.GetType());
#endif
                    m_DependentPropsCache.Add(dependencyPropertyArgs, dependentPropertyArgs);
                }
            }
        }
示例#13
0
 public PropertyChangedNotifyBase(INotifyPropertyChangedEx propertySource)
 {
     //m_DependentPropertyList = new List<KeyValuePair<string, string>>();
     InitializeDependentProperties(propertySource);
 }
 public ObservableProperty(INotifyPropertyChangedEx notifier, Expression <Func <TValue> > property) : this(default(TValue), notifier, property)
 {
 }
 public ObservableProperty(TValue defaultValue, INotifyPropertyChangedEx notifier, Expression <Func <TValue> > property) : this(defaultValue, notifier, property.GetMemberInfo().Name)
 {
 }
 public ObservableProperty(INotifyPropertyChangedEx notifier, string propertyName) : this(default(TValue), notifier, propertyName)
 {
 }