<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<TextBlock HorizontalAlignment="Left" Height="28" Margin="105,171,0,0" TextWrapping="Wrap" Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat=d}" VerticalAlignment="Top" Width="237"/>
<TextBlock HorizontalAlignment="Left" Height="28" Margin="105,220,0,0" TextWrapping="Wrap" Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" VerticalAlignment="Top" Width="237"/>
<Label Content="Label" HorizontalAlignment="Left" Margin="129,99,0,0" VerticalAlignment="Top" Background="AliceBlue" Width="163"/>
</Grid>
</Window>
这是一个WPF应用程序的代码示例,展示了如何在窗口中使用TextBlock展示当前日期和时间。两个TextBlock分别以不同的格式显示日期和时间,一个是短日期格式,另一个是带时分秒的完整日期时间格式。
1982

被折叠的 条评论
为什么被折叠?



