Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在datepicker dialouge片段上禁用最小日期_C#_Android_Xamarin_Xamarin.android_Datepicker - Fatal编程技术网

C# 如何在datepicker dialouge片段上禁用最小日期

C# 如何在datepicker dialouge片段上禁用最小日期,c#,android,xamarin,xamarin.android,datepicker,C#,Android,Xamarin,Xamarin.android,Datepicker,我正在使用下面的代码显示xamarin.android上的dialogefragment。我有两个问题 如何将默认选择的日期设置为当前日期(当前为该日期) 下个月有什么节目 如何在dialougefragment上禁用过去的日期 new DatePickerFragment(delegate (DateTime time) { var _selectedDate = time; txtDateTime.Text = _selectedDate.T

我正在使用下面的代码显示xamarin.android上的dialogefragment。我有两个问题

  • 如何将默认选择的日期设置为当前日期(当前为该日期) 下个月有什么节目
  • 如何在dialougefragment上禁用过去的日期

    new DatePickerFragment(delegate (DateTime time)
            {
    
            var _selectedDate = time;
            txtDateTime.Text = _selectedDate.ToString("yyyy.MM.dd");
    
        }) .Show(FragmentManager, DatePickerFragment.TAG);
    
  • 如何将默认选定日期设置为当前日期(当前显示为下个月)

    如果要将默认选定日期设置为当前日期,可以设置DatePickerDialog datetime

    DateTime currently = DateTime.Now;
    DatePickerDialog dialog = new DatePickerDialog(Activity, this, currently.Year, currently.Month,
                                                           currently.Day);
    dialog.DatePicker.DateTime = currently;
    
    如何在dialougefragment上禁用过去的日期

    new DatePickerFragment(delegate (DateTime time)
            {
    
            var _selectedDate = time;
            txtDateTime.Text = _selectedDate.ToString("yyyy.MM.dd");
    
        }) .Show(FragmentManager, DatePickerFragment.TAG);
    
    您可以将今天的日期设置为最短日期

    dialog.DatePicker.MinDate = Java.Lang.JavaSystem.CurrentTimeMillis();
    
    以下是DatePickerFragment.cs:

     public class DatePickerFragment : DialogFragment, DatePickerDialog.IOnDateSetListener
    {
        // TAG can be any string that you desire.
        public static readonly string TAG = "X:" + typeof (DatePickerFragment).Name.ToUpper();
        Action<DateTime> _dateSelectedHandler = delegate { };
    
        public void OnDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
        {
            // Note: monthOfYear is a value between 0 and 11, not 1 and 12!
            DateTime selectedDate = new DateTime(year, monthOfYear + 1, dayOfMonth);
            Log.Debug(TAG, selectedDate.ToLongDateString());
            _dateSelectedHandler(selectedDate);
        }
    
        public static DatePickerFragment NewInstance(Action<DateTime> onDateSelected)
        {
            DatePickerFragment frag = new DatePickerFragment();
            frag._dateSelectedHandler = onDateSelected;
            return frag;
        }
    
        public override Dialog OnCreateDialog(Bundle savedInstanceState)
        {
            DateTime currently = DateTime.Now;
            DatePickerDialog dialog = new DatePickerDialog(Activity, this, currently.Year, currently.Month,
                                                           currently.Day);
            dialog.DatePicker.DateTime = currently;
    
    
           dialog.DatePicker.MinDate = Java.Lang.JavaSystem.CurrentTimeMillis();
           
            return dialog;
        }
    }
    
    公共类DatePickerFragment:DialogFragment,DatePickerDialog.IOnDateSetListener { //标记可以是您想要的任何字符串。 公共静态只读字符串TAG=“X:”+typeof(DatePickerFragment).Name.ToUpper(); 动作_dateSelectedHandler=委托{}; 公共void OnDateSet(日期选择器视图,整数年,整数月,整数月) { //注意:monthOfYear是介于0和11之间的值,而不是介于1和12之间的值! DateTime selectedDate=新的日期时间(年、月+1、月天数); Log.Debug(标记,selectedDate.ToLongDateString()); _dateSelectedHandler(selectedDate); } 公共静态DatePickerFragment NewInstance(操作onDateSelected) { DatePickerFragment frag=新的DatePickerFragment(); frag.\u dateSelectedHandler=onDateSelected; 返回碎片; } 创建对话框上的公共覆盖对话框(Bundle savedInstanceState) { DateTime当前=DateTime.Now; DatePickerDialog=新建DatePickerDialog(活动,此,当前.Year,当前.Month, 当前(天); dialog.DatePicker.DateTime=当前; dialog.DatePicker.MinDate=Java.Lang.JavaSystem.CurrentTimeMillis(); 返回对话框; } } MainActivity.cs:

    public class MainActivity : Activity
    {
        TextView _dateDisplay;
        Button _dateSelectButton;
    
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
    
            _dateDisplay = FindViewById<TextView>(Resource.Id.date_display);
            _dateSelectButton = FindViewById<Button>(Resource.Id.date_select_button);
            _dateSelectButton.Click += DateSelect_OnClick;
        }
    
        void DateSelect_OnClick(object sender, EventArgs eventArgs)
        {
            DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time)
                                                                     {
                                                                        
                                                                         _dateDisplay.Text = time.ToLongDateString();
                                                                     });
            frag.Show(FragmentManager, DatePickerFragment.TAG);
        }
    }
    
    公共类main活动:活动
    {
    文本视图dateDisplay;
    按钮_dateSelectButton;
    创建时受保护的覆盖无效(捆绑包)
    {
    base.OnCreate(bundle);
    SetContentView(Resource.Layout.Main);
    _dateDisplay=findviewbyd(Resource.Id.date\u display);
    _dateSelectButton=FindViewById(Resource.Id.date\u选择按钮);
    _dateSelectButton。单击+=日期选择\u OnClick;
    }
    void DateSelect\u OnClick(对象发送方,EventArgs EventArgs)
    {
    DatePickerFragment frag=DatePickerFragment.NewInstance(委托(日期时间)
    {
    _dateDisplay.Text=time.ToLongDateString();
    });
    显示(FragmentManager,DatePickerFragment.TAG);
    }
    }
    
    截图:


    您是否尝试过DateTime。现在,对于当前日期,我在哪里可以设置它?在上面的代码中?对于2)dialog.DatePicker.MinDate=Java.Lang.JavaSystem.CurrentTimeMillis();对话类型为DatePickerDialogvar\u selectedDate=time。现在..试试看,先生,此拨号没有对象。仅使用上述代码来显示片段,您能否在上述代码的上下文中详细说明?