Exemplo n.º 1
0
        public TabViewModel(Tab model, InteractionMessenger mainWindowViewModelMessenger)
        {
            this.model = model;
            this.Messenger = mainWindowViewModelMessenger;

            ViewModelHelper.BindNotifyChanged(model, this, (sender, e) =>
            {
                switch (e.PropertyName)
                {
                    case "Name":
                    case "IsRefreshing":
                        this.RaisePropertyChanged(e.PropertyName);
                        break;
                    case "LastErrorMessage":
                        this.RaisePropertyChanged(e.PropertyName);
                        this.RaisePropertyChanged(() => this.LastErrorMessageIsNotEmpty);
                        break;
                }
            });

            var source = new CollectionViewSource();
            source.Source = ViewModelHelper.CreateReadOnlyDispatcherCollection(
                model.Items,
                (ITimelineItem item) =>
                {
                    var re = new TimelineItemViewModel(item);
                    ViewModelHelper.BindNotifyChanged(re, this, (sender, e) =>
                    {
                        if (e.PropertyName == "IsSelected")
                        {
                            var vm = (TimelineItemViewModel)sender;
                            if (vm.IsSelected)
                                this.SelectedItems.Add(vm);
                            else
                                this.SelectedItems.Remove(vm);
                        }
                    });
                    return re;
                },
                DispatcherHelper.UIDispatcher
            );
            source.SortDescriptions.Clear();
            source.SortDescriptions.Add(new SortDescription("CreatedAt", ListSortDirection.Descending));
            source.SortDescriptions.Add(new SortDescription("Id", ListSortDirection.Descending));
            this.Items = source.View;

            this.SelectedItems = new ObservableCollection<TimelineItemViewModel>();
        }
Exemplo n.º 2
0
 public void AddTab(TabSetting setting, int index)
 {
     var tab = new Tab(setting);
     this.Tabs.Insert(index, tab);
 }
Exemplo n.º 3
0
 private TabViewModel CreateTabViewModel(Tab model)
 {
     var re = new TabViewModel(model, this.Messenger);
     ViewModelHelper.BindNotifyCollectionChanged(re.SelectedItems, this, (sender, e) =>
     {
         this.ReplyCommand.RaiseCanExecuteChanged();
     });
     return re;
 }