Wednesday 29 February 2012

How to bind Current Date Time to TextBlock - XAML

Create a Following Namespace 


xmlns:sys="clr-namespace:System;assembly=mscorlib"


 To Show the Current date time .


<TextBlock  Name="tbArrivalDateTime"
            Text="{Binding Source={x:Static sys:DateTime.Now},
                   StringFormat='{}{0:dd-MMM-yyyy hh:mm:ss}'}"
                   VerticalAlignment="Center"
                   Grid.Row="3"
                   Grid.Column="1"
                   Margin="10,0,0,0"
                   HorizontalAlignment="Left"/>

 To Show the Current date only .

<TextBlock  Name="tbArrivalDateTime"
            Text="{Binding Source={x:Static sys:DateTime.Today},
                   StringFormat='{}{0:dd-MMM-yyyy}'}"
                   VerticalAlignment="Center"
                   Grid.Row="3"
                   Grid.Column="1"
                   Margin="10,0,0,0"
                   HorizontalAlignment="Left"/>

3 comments:

  1. Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime. See the link below for more info.


    #lifetime
    www.ufgop.org

    ReplyDelete
  2. Nice post. I learn one thing more difficult on totally different blogs everyday. It can always be stimulating to learn content material from different writers and apply slightly something from their store. I’d desire to use some with the content material on my weblog whether or not you don’t mind. Natually I’ll give you a link on your internet blog. Thanks for sharing. online casinos

    ReplyDelete
  3. Who knew date time formatting can inspire so many people! Seems like you are truli doing the lords work.
    Anyway... the string format didnt work for me so I guess you've inspired me to go find a solution elsewhere?

    ReplyDelete