Exemplo n.º 1
0
        public override void LoadView()
        {
            var view = new NSView();

            var lblTitle = new NSTextField
            {
                Editable    = false,
                Hidden      = string.IsNullOrEmpty(this.Title),
                Alignment   = NSTextAlignment.Center,
                StringValue = this.Title ?? string.Empty
            };

            var datePicker = new NSDatePicker
            {
                DatePickerStyle    = NSDatePickerStyle.ClockAndCalendar,
                DatePickerElements = this.ElementFlags,
                DateValue          = this.SelectedDateTime.ToNSDate(),
                TimeInterval       = this.MinuteInterval
            };

            if (this.Use24HourClock)
            {
                datePicker.Locale = NSLocale.FromLocaleIdentifier("NL");
            }

            if (this.MaximumDateTime != null)
            {
                datePicker.MinDate = this.MaximumDateTime.Value.ToNSDate();
            }

            if (this.MaximumDateTime != null)
            {
                datePicker.MaxDate = this.MaximumDateTime.Value.ToNSDate();
            }

            var okButton = new NSButton
            {
                Title = this.OkText
            };

            okButton.Activated += (sender, e) =>
            {
                this.SelectedDateTime = datePicker.DateValue.ToDateTime();
                this.Presentor.DismissViewController(this);
                this.Ok?.Invoke(this);
            };

            var cancelButton = new NSButton
            {
                Title = this.CancelText
            };

            cancelButton.Activated += (sender, e) =>
            {
                this.Presentor.DismissViewController(this);
                this.Cancel?.Invoke(this);
            };

            view.AggregateSubviews(lblTitle, datePicker, okButton, cancelButton);

            // Constraints
            Extensions.ActivateConstraints(
                lblTitle.TopAnchor.ConstraintEqualToAnchor(view.TopAnchor),
                lblTitle.LeadingAnchor.ConstraintEqualToAnchor(view.LeadingAnchor),
                lblTitle.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor),

                datePicker.TopAnchor.ConstraintEqualToAnchor(lblTitle.BottomAnchor, 2),
                datePicker.LeadingAnchor.ConstraintEqualToAnchor(view.LeadingAnchor),
                datePicker.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor),

                okButton.TopAnchor.ConstraintEqualToAnchor(datePicker.BottomAnchor, 2),
                okButton.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor),
                okButton.BottomAnchor.ConstraintEqualToAnchor(view.BottomAnchor),

                cancelButton.TrailingAnchor.ConstraintEqualToAnchor(okButton.LeadingAnchor, 2),
                cancelButton.LeadingAnchor.ConstraintGreaterThanOrEqualToAnchor(view.LeadingAnchor),
                cancelButton.BottomAnchor.ConstraintEqualToAnchor(okButton.BottomAnchor)
                );

            this.View = view;
        }
Exemplo n.º 2
0
        public ProgressDialog(ProgressDialogConfig config)
        {
            this.config     = config;
            this.title      = config.Title;
            this.mainWindow = NSApplication.SharedApplication.KeyWindow;

            progressPanel = new NSPanel(new CGRect(0, 0, 100, 140), NSWindowStyle.DocModal, NSBackingStore.Buffered, true)
            {
                BackgroundColor = NSColor.White
            };

            var view = new NSView();

            txtTitle = new NSTextField
            {
                Editable  = false,
                Hidden    = string.IsNullOrEmpty(this.title),
                Alignment = NSTextAlignment.Center
            };

            progressIndicator = new NSProgressIndicator
            {
                Style         = NSProgressIndicatorStyle.Spinning,
                Indeterminate = !config.IsDeterministic,
                MinValue      = 0,
                DoubleValue   = 0,
                MaxValue      = 100
            };

            view.AggregateSubviews(txtTitle, progressIndicator);

            NSButton cancelButton = null;

            if (config.OnCancel != null)
            {
                cancelButton = new NSButton
                {
                    Title = config.CancelText
                };
                cancelButton.Activated += (sender, e) =>
                {
                    Hide(true);
                };

                view.AggregateSubviews(cancelButton);
            }

            txtTitle.TopAnchor.ConstraintEqualToAnchor(view.TopAnchor).Active           = true;
            txtTitle.LeadingAnchor.ConstraintEqualToAnchor(view.LeadingAnchor).Active   = true;
            txtTitle.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor).Active = true;

            progressIndicator.TopAnchor.ConstraintEqualToAnchor(txtTitle.BottomAnchor, 2).Active = true;
            progressIndicator.LeadingAnchor.ConstraintEqualToAnchor(view.LeadingAnchor).Active   = true;
            progressIndicator.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor).Active = true;
            progressIndicator.HeightAnchor.ConstraintEqualToConstant(100).Active = true;
            progressIndicator.WidthAnchor.ConstraintEqualToConstant(100).Active  = true;

            if (cancelButton == null)
            {
                progressIndicator.BottomAnchor.ConstraintLessThanOrEqualToAnchor(view.BottomAnchor).Active = true;
            }
            else
            {
                cancelButton.TopAnchor.ConstraintEqualToAnchor(progressIndicator.BottomAnchor, 2).Active = true;
                cancelButton.CenterXAnchor.ConstraintEqualToAnchor(view.CenterXAnchor).Active            = true;
                cancelButton.BottomAnchor.ConstraintLessThanOrEqualToAnchor(view.BottomAnchor).Active    = true;
            }

            progressPanel.ContentView = view;
        }