簡體   English   中英

wpfx:DateTimePicker如何手動設置日期和時間

[英]wpfx:DateTimePicker how to set date and time manually

我有

wpfx:DateTimePicker x:Name =“ dat_reg”

我想現在在窗口上設置日期和時間,我該怎么做。 我的代碼是<wpfx:DateTimePicker x:Name="dat_reg" Height="23" Margin="223,270,184,-237" Grid.ColumnSpan="3"></wpfx:DateTimePicker>

  public frm_main()
    {
        InitializeComponent();
        //dat_reg.SetValue(DateTime.Now.ToShortDateString());

    }

但這行不通。謝謝

而不是設置值,而是使用DateTimePicker SelectedDate屬性。 您可以使用DateTime類型存儲日期和時間,無需將其轉換為string類型

public frm_main()
    {
        InitializeComponent();
        dat_reg.SelectedDate= DateTime.Now;
        //dat_reg.SelectedDate = new DateTime(2018, 05, 07); 
       //In this way you can assign instance of DateTime with specific Date and time

    }

設置Value屬性和FormatString屬性:

dat_reg.Value = DateTime.Now;
dat_reg.Format = Xceed.Wpf.Toolkit.DateTimeFormat.DateTimeFormat.Custom; 
dat_reg.FormatString = "d"; 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM