繁体   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