Пример #1
0
        public CollectionEditor() : base()
        {
            Uri resourceLocater = new Uri("/UtilityWpf.View;component/Themes/CollectionEditor.xaml", System.UriKind.Relative);
            ResourceDictionary resourceDictionary = (ResourceDictionary)Application.LoadComponent(resourceLocater);

            Style = resourceDictionary["CollectionEditorStyle"] as Style;

            //DeletedSubject.OnNext(new object());

            //NewItemS
            //Observable.FromEventPattern<EventHandler, EventArgs>(_ => this.Initialized += _, _ => this.Initialized -= _)
            //  .CombineLatest(NewItemsSubject, (a, b) => b)
            //     .CombineLatest(KeySubject, (item, key) => new { item, key })
            //  .Subscribe(_ => React(_.item, _.key));

            var obs = ItemsSourceSubject.Where(_ => _ != null)
                      .Take(1)
                      .Select(_ => (_.First()))
                      .Concat(SelectedItemSubject)
                      .DistinctUntilChanged();

            InputSubject.WithLatestFrom(obs, (input, item) => new { input, item })
            .Subscribe(_ =>
            {
                switch (_.input)
                {
                case (DatabaseCommand.Delete):
                    DeletedSubject.OnNext(_.item);
                    break;

                case (DatabaseCommand.Update):

                    break;

                case (DatabaseCommand.Clear):
                    ClearedSubject.OnNext(null);
                    break;
                }
            });

            Action <DatabaseCommand> av = (a) => this.Dispatcher.InvokeAsync(() => InputSubject.OnNext(a), System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));

            var items = ButtonDefinitionHelper.GetCommandOutput <DatabaseCommand>(typeof(DatabaseCommand))
                        ?.Select(meas =>
                                 new ViewModel.ButtonDefinition
            {
                Command = new RelayCommand(() => av(meas.Value())),
                Content = meas.Key
            });

            if (items == null)
            {
                Console.WriteLine("measurements-service equals null in collectionviewmodel");
            }
            else
            {
                this.Dispatcher.InvokeAsync(() => Buttons = items.ToList(), System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            }
        }
Пример #2
0
        protected override void ChangeItemsSource(System.Collections.IEnumerable value)
        {
            var t     = value.First();
            var type  = t.GetType();
            var props = type.GetProperties();
            //var fields = type.GetFields();

            var value2 = value.Cast <object>().Select(_ => props.Select(__ => new[] { new KeyValuePair <string, string>(__.Name, __.GetValue(_).ToString()) }));

            //.Concat(fields.Select(__ => new[] { new KeyValuePair<string, string>(__.Name, __.GetValue(_).ToString()) })));
            //new KeyValuePair<string, string>(
            ItemsSourceSubject.OnNext(value2);
        }
Пример #3
0
 protected virtual void ChangeItemsSource(IEnumerable value)
 {
     ItemsSourceSubject.OnNext((IEnumerable)value);
 }