locked
date time (angel) - 1/2/2008 6:53 AM PST RRS feed

  • Question

  • By: angel


    hi.. i wonder how should i display current time and current date in my 
    application using wpf c# ?
    Friday, February 22, 2008 3:25 PM

All replies

  • Corrado Cavalli [MVP]


    Quickest way is to add a texblock (textblock1) and in the window's 
    constructor add
    
       string info=string.Format("Todays is {0} current time is: 
    {1}",DateTime.Now.ToShortDateString(),DateTime.Now.ToShortTimeString());
       textBlock1.Text = info;
    
    Of course this text is static, you'd use a dispatchertimer to dinamically 
    update it.
    
    HTH
    
    -- 
    Corrado Cavalli [Microsoft .NET MVP-MCP]
    UGIdotNET - http://www.ugidotnet.org
    Weblog: http://blogs.ugidotnet.org/corrado/ 
    
    
    Friday, February 22, 2008 11:33 PM
  • Brennon Williams


    Howdy Angel,
    
    Do you specifically need it provided from inside the code behind?
    
    You could bind the value directly from System.DateTime clr object.
    
    
    <Window.Resources>
    	<ObjectDataProvider x:Key="DateTimeDS" d:IsDataSource="True" 
    ObjectType="{x:Type System:DateTime}"/>
    </Window.Resources>
    
    
    <Grid x:Name="LayoutRoot">
    	<TextBox BorderBrush="{x:Null}"
    FontSize="36" HorizontalAlignment="Center" Margin="8,8,0,0" 
    VerticalAlignment="Center" Width="Auto" Height="Auto" Text="{Binding 
    Path=Now, Mode=OneWay, Source={StaticResource DateTimeDS}}" 
    TextWrapping="Wrap"/>
    
    </Grid>
    
    
    HTH
    
    Cheers
    -- 
    Want to learn how to use Blend and visual studio?
    
    http://www.learnexpressionstudio.com
    http://www.expressionblend.com
    http://www.x-coders.com
    
    
    "angel" wrote:
    
    > hi.. i wonder how should i display current time and current date in my 
    > application using wpf c# ?
    Friday, February 22, 2008 11:33 PM