WPF DateTimePicker
来源:互联网 发布:mac 切换 输入法 编辑:程序博客网 时间:2024/06/18 15:10
WPF没有DateTimePicker,自身的DatePicker不能选择时间。所以要自己实现。
<DatePicker Height="25" Width="250" Text="2011/10/11 15:16:17"/>
- 使用WinForm的DateTimePicker
<Window x:Class="WinFormDateTimePicker.MainWindow"...xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"> <Grid> <StackPanel> <wfi:WindowsFormsHost Width="190" Margin="5"> <wf:DateTimePicker x:Name="dtp1" Format="Custom" CustomFormat="yyyy年MM月dd日 HH:mm:ss" ShowUpDown="False" Text="2011/10/11 9:10:11"/> </wfi:WindowsFormsHost> <wfi:WindowsFormsHost Width="190" Margin="5"> <wf:DateTimePicker x:Name="dtp2" Format="Custom" CustomFormat="yyyy/MM/dd hh:mm:ss" ShowUpDown="False" Text="2011/10/11 9:10:11"/> </wfi:WindowsFormsHost> <wfi:WindowsFormsHost Width="190" Margin="5"> <wf:DateTimePicker x:Name="dtp3" Format="Custom" CustomFormat="yyyy-MM-dd hh:mm:ss" ShowUpDown="False" Text="2011/10/11 9:10:11"/> </wfi:WindowsFormsHost> <wfi:WindowsFormsHost Width="190" Margin="5"> <wf:DateTimePicker x:Name="dtp4" Format="Custom" CustomFormat="yyyy年MM月dd日" ShowUpDown="False" Text="2011/10/11 9:10:11"/> </wfi:WindowsFormsHost> <wfi:WindowsFormsHost Width="190" Margin="5"> <wf:DateTimePicker x:Name="dtp5" Format="Custom" CustomFormat="yyy/MM/dd" ShowUpDown="False" Text="2011/10/11 9:10:11"/> </wfi:WindowsFormsHost> <wfi:WindowsFormsHost Width="190" Margin="5"> <wf:DateTimePicker x:Name="dtp6" Format="Custom" CustomFormat="yyyy-MM-dd" ShowUpDown="False" Text="2011/10/11 9:10:11"/> </wfi:WindowsFormsHost> <wfi:WindowsFormsHost Width="190" Margin="5"> <wf:DateTimePicker x:Name="dtp7" Format="Custom" CustomFormat="HH:mm:ss" ShowUpDown="False" Text="2011/10/11 9:10:11"/> </wfi:WindowsFormsHost> </StackPanel> </Grid></Window>
- 使用Wpf.Toolkit
<Window x:Class="WpfDateTimePicker.MainWindow" ... xmlns:wpfx="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"> <Grid> <StackPanel> <wpfx:DateTimePicker x:Name="DateTimePicker1" Height="25" Width="250" Margin="5" ShowButtonSpinner="False" Format="Custom" FormatString="yyyy年MM月dd日 HH:mm:ss" Text=" 年 月 日 : :"/> <wpfx:DateTimePicker x:Name="DateTimePicker2" Height="25" Width="250" Margin="5" ShowButtonSpinner="False" Format="Custom" FormatString="yyyy/MM/dd hh:mm:ss" Text="2011/10/11 15:16:17"/> <wpfx:DateTimePicker x:Name="DateTimePicker3" Height="25" Width="250" Margin="5" ShowButtonSpinner="False" Format="Custom" FormatString="yyyy-MM-dd hh:mm:ss" Text="2011/10/11 15:16:17"/> <wpfx:DateTimePicker x:Name="DateTimePicker4" Height="25" Width="250" Margin="5" ShowButtonSpinner="False" Format="Custom" FormatString="yyyy年MM月dd日" Text="2011年10月11日"/> <wpfx:DateTimePicker x:Name="DateTimePicker5" Height="25" Width="250" Margin="5" ShowButtonSpinner="False" Format="Custom" FormatString="yyyy/MM/dd" Text="2011/10/11"/> <wpfx:DateTimePicker x:Name="DateTimePicker6" Height="25" Width="250" Margin="5" ShowButtonSpinner="False" Format="Custom" FormatString="yyyy-MM-dd" Text="2011/10/11"/> <wpfx:DateTimePicker x:Name="DateTimePicker7" Height="25" Width="250" Margin="5" ShowButtonSpinner="False" Format="Custom" FormatString="HH:mm:ss" Text="15:16:17"/> <wpfx:DateTimePicker x:Name="DateTimePicker8" Height="25" Width="250" Margin="5" ShowButtonSpinner="False" Format="Custom" FormatString="yyyy/MM/dd" Text="2011/10/11"/> </StackPanel> </Grid></Window>
3.UserControl
<UserControl x:Class="MyDTPicker.DateTimePicker" ... xmlns:local="clr-namespace:MyDTPicker" mc:Ignorable="d"> <StackPanel Orientation="Horizontal"> <TextBox x:Name="DateDisplay" VerticalContentAlignment="Center" Margin="0,0,0,0" MinHeight="{Binding ElementName=PopUpCalendarButton, Path=ActualHeight}" >2017-10-23 12:30</TextBox> <ToggleButton Background="{Binding Path=Background}" MaxHeight="21" Margin="-1,0,0,0" Name="PopUpCalendarButton" IsChecked="False"> <Grid x:Name="arrowGlyph" Grid.Column="1" IsHitTestVisible="False" Margin="5"> <Path x:Name="Arrow" Data="M0,0L3,0 4.5,1.5 6,0 9,0 4.5,4.5z" Fill="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Height="5" Margin="0,1,0,0" Width="9"/> </Grid> </ToggleButton> <Popup IsOpen="{Binding Path=IsChecked, ElementName=PopUpCalendarButton}" x:Name="CalendarPopup" Margin="0,-7,0,0" PopupAnimation="Fade" StaysOpen="False"> <Calendar Margin="0,-1,0,0" x:Name="CalDisplay"/> </Popup> </StackPanel></UserControl>
阅读全文
0 0
- WPF DateTimePicker
- WPF DateTimePicker focus 焦点问题
- WPF DateTimePicker显示时分秒
- DateTimePicker
- DateTimePicker
- DateTimePicker
- DateTimePicker
- DateTimePicker
- datetimepicker
- DateTimePicker
- datetimepicker
- DateTimePicker
- WPF 自定义DateTimePicker控件,实现时间设置与选择
- 如何改变格式的DateTimePicker的WPF应用程序(例如日/ MMM /年)
- datetimepicker格式化
- DateTimePicker控件
- dateTimePicker控件
- struts2 datetimepicker
- L1-012. 计算指数
- 视觉slam14讲——第5讲 相机与图像
- 通过修改hosts访问外网
- 10个方法让你的私人时间妥妥的
- 时间戳毫秒数转换日期 日期转换时间戳毫秒数
- WPF DateTimePicker
- 【腾讯TMQ】像google一样测试系列之五:流程与覆盖率篇
- 重复add或update导致ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
- 大小堆之堆排序
- HTML 注册表单form
- Servlet 工程 web.xml 中的 servlet 和 servlet-mapping 标签
- Android获取手机双IMEI号
- Linux裸机下搭建各种服务(第一篇)
- U盘安装Ubuntu