xamarin/Xamarin.Forms

[Bug] Android TimePickerRenderer dialog positive button handler not triggered

开放

#13,022 创建于 2020年12月2日

 (1 条评论) (0 个反应) (0 位负责人)C# (1,926 个派生)batch import
a/customrenderera/timepickere/2 :clock2:help wantedp/Androidt/bug :bug:up-for-grabs

仓库指标

星标
 (5,644 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Description

When implementing a custom renderer for the TimePicker in Android to intercept whether the dialogs OK button is pressed, the handler is not triggered for the DialogButtonType.Positive. Negative and Neutral button handlers are triggered.

The same code is working for DatePickerRenderer

Steps to Reproduce

    protected override TimePickerDialog CreateTimePickerDialog(int hours, int minutes)
    {
        dialog = new TimePickerDialog(Context, this, hours, minutes, true);

        dialog.SetButton((int) DialogButtonType.Negative,
            Context.Resources.GetString(global::Android.Resource.String.Cancel), OnCancel);
        dialog.SetButton((int) DialogButtonType.Positive,
            Context.Resources.GetString(global::Android.Resource.String.Ok), OnOk);
        
        return dialog;
    }

    private void OnCancel(object sender, DialogClickEventArgs e)
    {
        _element.Unfocus();
    }

    private void OnOk(object sender, EventArgs eventArgs)
    {
        _element.Unfocus();
    }

Expected Behavior

When clicking the OK button OnOk is called. When clicking the Cancel button OnCancel is called.

Actual Behavior

When clicking the OK button OnOk is NOT called. When clicking the Cancel button OnCancel is called.

Basic Information

  • Version with issue: 4.8.0.1678
  • Last known good version: -
  • Platform Target Frameworks:
    • Android: TargetSDK: 30

Workaround

Instead I need to use the following code in my control:

this.PropertyChanged += (sender, args) =>
            {
                if (Device.RuntimePlatform != Device.Android || args.PropertyName != "Time")
                {
                    return;
                }

                CallOnOk();
            };

贡献者指南