Example #1
0
        public MasterListPage()
        {
            InitializeComponent();
            ViewModel = (MasterListViewModel)App.Container.Resolve <IMasterListViewModel>();
            //this.BindingContext = vm;
            Title = ViewModel.defaultsFactory.GetAppName();

            var dtemplate = new DataTemplate(() =>
            {
                var stacklayout = new StackLayout()
                {
                    Orientation       = StackOrientation.Horizontal,
                    Padding           = new Thickness(10, 10, 10, 10),
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand
                };
                var lbl   = new LabelForReactive();
                var ffimg = new ImageForReactive();
                stacklayout.Children.Add(ffimg);

                stacklayout.Children.Add(lbl);
                return(new ViewCell {
                    View = stacklayout
                });
            });


            listView = new ListView()
            {
                HasUnevenRows       = false,
                SeparatorVisibility = SeparatorVisibility.None,
                HorizontalOptions   = LayoutOptions.FillAndExpand,
                BackgroundColor     = ViewModel.defaultsFactory.GetSideMenuColor(),
                ItemTemplate        = dtemplate
            };
            //listView.SetBinding(ListView.ItemsSourceProperty, new Binding("Items"));


            this
            .WhenActivated(
                disposables =>
            {
                this
                .OneWayBind(this.ViewModel, x => x.FontSize, x => x.listView.RowHeight, vmToViewConverterOverride: bindingIntToDoubleConverter)
                .DisposeWith(disposables);
                this
                .OneWayBind(this.ViewModel, x => x.Items, x => x.listView.ItemsSource)
                .DisposeWith(disposables);
            });
            Content = listView;
        }
        public OrganizationPage()
        {
            InitializeComponent();
            ViewModel  = (OrganizationPageViewModel)App.Container.Resolve <IOrganizationPageViewModel>();
            viewAction = new MenuItem {
                Text = "View"
            };
            viewAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));

            editAction = new MenuItem {
                Text = "Edit"
            };
            editAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
            baseLayout = new StackLayout()
            {
                Orientation       = StackOrientation.Vertical,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center
            };
            var dtemplate = new DataTemplate(() =>
            {
                var stacklayout = new StackLayout()
                {
                    Orientation       = StackOrientation.Horizontal,
                    Padding           = new Thickness(10, 10, 10, 10),
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand
                };
                var lbl = new LabelForReactive();


                var ffimg = new ImageForReactive();
                stacklayout.Children.Add(ffimg);

                stacklayout.Children.Add(lbl);
                var viewCell = new ViewCell();

                //deleteAction.Clicked += OnDelete;

                viewCell.ContextActions.Add(viewAction);
                viewCell.ContextActions.Add(editAction);
                viewCell.View = stacklayout;
                return(viewCell);
            });

            listView = new ListView()
            {
                HasUnevenRows       = false,
                SeparatorVisibility = SeparatorVisibility.None,
                HorizontalOptions   = LayoutOptions.FillAndExpand,
                BackgroundColor     = Color.White,
                ItemTemplate        = dtemplate
            };
            this
            .WhenActivated(
                disposables =>
            {
                Observable.FromEventPattern(
                    ev => viewAction.Clicked += ev,
                    ev => viewAction.Clicked -= ev
                    )
                .Subscribe(x =>
                {
                    OnView(x.Sender, x.EventArgs as EventArgs);
                })
                .DisposeWith(disposables);

                Observable.FromEventPattern(
                    ev => editAction.Clicked += ev,
                    ev => editAction.Clicked -= ev
                    )
                .Subscribe(x =>
                {
                    OnEdit(x.Sender, x.EventArgs as EventArgs);
                })
                .DisposeWith(disposables);

                Observable.FromEventPattern <SelectedItemChangedEventArgs>(
                    ev => listView.ItemSelected += ev,
                    ev => listView.ItemSelected -= ev
                    )
                .Subscribe(x =>
                {
                    OnSelection(x.Sender, x.EventArgs);
                })
                .DisposeWith(disposables);

                Observable.FromEventPattern <ItemTappedEventArgs>(
                    ev => listView.ItemTapped += ev,
                    ev => listView.ItemTapped -= ev
                    )
                .Subscribe(x =>
                {
                    OnTap(x.Sender, x.EventArgs);
                })
                .DisposeWith(disposables);

                this
                .OneWayBind(ViewModel, vm => vm.Title, x => x.Title)
                .DisposeWith(disposables);
                this
                .OneWayBind(this.ViewModel, x => x.FontSize, x => x.listView.RowHeight, vmToViewConverterOverride: bindingIntToDoubleConverter)
                .DisposeWith(disposables);
                this
                .OneWayBind(this.ViewModel, x => x.Items, x => x.listView.ItemsSource)
                .DisposeWith(disposables);
            });
            baseLayout.Children.Add(listView);
            Content = baseLayout;
        }