Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Opening a datepicker view with the click event button in a toolbar item

$
0
0

Hello

I have a datepicker inside a stacklayout, what i want to do is open the datepicker when the user clicks a button (any button)

DatePicker startDate = new DatePicker
            {
                Format = "D",
                BackgroundColor = Color.Green,
                WidthRequest = width,
                MinimumDate = today,
            };

I have achieve this in android with the dependency service and using a "DatePickerDialog dialog"

but in windows phone I can't figure this out, I am currently doing something like this (in the windows phone class):

Microsoft.Phone.Controls.DatePicker test = new Microsoft.Phone.Controls.DatePicker();
Microsoft.Phone.Controls.DatePickerPage testie = new DatePickerPage();

        public PickerRenderer() 
        {
            test.Width = 0;
            testie.Width = 0;
            test.Height = 0;
            testie.Height = 0;
            this.Content = testie;
        }
        public void buttonClicked(Label aLbl)
        {
            test.Focus();
            testie.Focus();
        }

I have also tried gaining the focus of the element in Xamarin.forms like this:

if (Device.OS == TargetPlatform.WinPhone)
            {

                mainLayout.Children.Add(startDate);
                toolbarItem = new ToolbarItem("Add", "plus.png", () =>
                {

                    startDate.Focus();
                }, 0, 0);
                ToolbarItems.Add(toolbarItem); 
            }

But without any success, also there isn't a datepicker.open() or datepicker.show() function.

Any other ideas?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>