public CounterPage()
        {
            InitializeComponent();

            // Observe changes on state
            Store.Select(SelectCount)
            .UntilDestroyed(this)
            .Subscribe(count =>
            {
                CounterValueTextBlock.Text = count.ToString();
            });

            // Observe UI events
            IncrementButton.Events().Click
            .Subscribe(_ => Store.Dispatch(new IncrementAction()));

            DecrementButton.Events().Click
            .Subscribe(_ => Store.Dispatch(new DecrementAction()));

            // Initialize Documentation
            DocumentationComponent.LoadMarkdownFilesAsync("Counter");

            GoToGitHubButton.Events().Click
            .Subscribe(async _ =>
            {
                var uri = new Uri("https://github.com/Odonno/ReduxSimple/tree/master/ReduxSimple.Samples/Counter");
                await Launcher.LaunchUriAsync(uri);
            });

            OpenDevToolsButton.Events().Click
            .Subscribe(async _ =>
            {
                await Store.OpenDevToolsAsync();
            });

            ContentGrid.Events().Tapped
            .Subscribe(_ => DocumentationComponent.Collapse());
            DocumentationComponent.ObserveOnExpanded()
            .Subscribe(_ => ContentGrid.Blur(5).Start());
            DocumentationComponent.ObserveOnCollapsed()
            .Subscribe(_ => ContentGrid.Blur(0).Start());
        }
Beispiel #2
0
        private void WireEvents(Action<string> returnString, Action<double> returnDouble) 
        {

            OKButton.Events().Clicked
                .Subscribe(x => PopupNavigation.Instance.PopAsync());

            IncrementButton.Events().Clicked
                .Subscribe(x =>
                {
                    if (StepMode == StepMode.Discrete)
                    {
                        if (slider.Value < Items.Count) slider.Value++;
                    } 
                    else if (StepMode == StepMode.Normal)
                    {
                        if (slider.Value + Step <= slider.Maximum) slider.Value += Step;
                    } else
                    {
                        // change by .1 percent
                        var increment = GetFriendlyIncrement();
                        var newValue = slider.Value + increment;
                        slider.Value = Math.Round(newValue / increment) * increment;
                    }
                });


            DecrementButton.Events().Clicked
                .Subscribe(x =>
                {
                    if (StepMode == StepMode.Discrete)
                    {
                        if (slider.Value < Items.Count) slider.Value--;
                    } 
                    else if (StepMode == StepMode.Normal)
                    {
                        if (slider.Value - Step >= slider.Minimum) slider.Value -= Step;
                    } else
                    {
                        // change by .1 percent
                        var increment = GetFriendlyIncrement();
                        var newValue = slider.Value - increment;
                        slider.Value = Math.Round(newValue / increment) * increment;
                    }
                });

            slider.Events().ValueChanged
                .SubscribeOnUI()
                //.Throttle(TimeSpan.FromMilliseconds(1))
                .Subscribe(X => 
                {
                    SetToNearestStep();
                    DrawSliderLabel();
                    if (returnDouble != null)
                    {
                        if (StepMode == StepMode.Discrete && double.TryParse(SelectedItem, out var dbl))
                        {
                            returnDouble(dbl);
                        }
                        else
                        {
                            returnDouble(slider.Value);
                        }
                    }
                    else if (returnString != null)
                    {
                        returnString((string)SelectedItem);
                    }
                });

            this.Events().LayoutChanged
                .SubscribeOnUI()
                .Subscribe(x => {
                    if (slider.Width > 0)
                    {
                        DrawTicks();
                        DrawSliderLabel();
                    }
                });
        }