Quantcast
Channel: xaml – AuthorCode
Viewing all articles
Browse latest Browse all 3

Show Date time in xaml

$
0
0

 
The following is the small example for displaying current datetime in XAML.
 
In XAML you need to first add the mscorlib assembly and the System namespace, then you can use use the {x:Static sys:DateTime.Now} in your code like this:
 

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="MainWindow" Height="279" Width="454">
    <Grid>
        <TextBox Height="20" Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='dd/MM/yyyy hh:mm tt'}" />
    </Grid>
</Window>

 
You can use the string format to display the datatime in various format.
Suppose if you want to show date in long form you can use the following code:

Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='D'}"

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images