Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8106093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:21:25+00:00 2026-06-06T00:21:25+00:00

Using WPF, and VB.net, I want to update a textbox in a textblock with

  • 0

Using WPF, and VB.net, I want to update a textbox in a textblock with the current date and time. I use a timer, and it seems to be firing, and setting an object property to “Now”.
And I am using iNotifyPropertyChanged.

All I get is an empty textbox with no data in it. Can you help? Maybe my context is off?

XAML

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
    <TextBlock DataContext="oTime"> 
        <TextBox x:Name="myTextBox" 
                 Width="200" Height="50" Foreground="Black" 
                 Text="{Binding Path=oTime.TimeUpdate}"></TextBox>
    </TextBlock>
</Grid>
</Window>

VB Code

Imports System.ComponentModel
Imports System.Windows.Threading

Class MainWindow
  Public oTime As TimeUpdate = New TimeUpdate
  Private dpTimer As DispatcherTimer

  Private Sub TextBlock_SourceUpdated(ByVal sender As System.Object, ByVal e As System.Windows.Data.DataTransferEventArgs)

  End Sub

  Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
      dpTimer = New DispatcherTimer
      dpTimer.Interval = TimeSpan.FromMilliseconds(1000)
      AddHandler dpTimer.Tick, AddressOf TickMe
      dpTimer.Start()
  End Sub

  Private Sub TickMe()
      oTime.TimeUpdate = Now.ToString
      Debug.Print(oTime.TimeUpdate)
  End Sub

End Class

Public Class TimeUpdate
Implements INotifyPropertyChanged

  Private sTime As String

  'Declare the Event
  Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

  Public Property TimeUpdate() As String
      Get
          Return sTime

      End Get
      Set(ByVal value As String)
          sTime = value
          'Call onPropertyChanged whenever the property is updated
          OnPropertyChanged("TimeUpdate")
      End Set

  End Property

  Protected Sub OnPropertyChanged(ByVal name As String)
      RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
  End Sub

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:21:27+00:00Added an answer on June 6, 2026 at 12:21 am

    Few things seem to be missing. First the DataContext of the window is not set. You can do it the constructor:

    Public Sub New()
        DataContext = oTime
    End Sub
    

    This allows your view to see the contents of the TimeUpdate class.

    And then change you XAML (bind directly to the TimeUpdate property):

    <Grid> 
        <TextBox x:Name="myTextBox" 
                 Width="200" Height="50" Foreground="Black" 
                 Text="{Binding Path=TimeUpdate}"></TextBox>
    </Grid>
    

    Update:
    Alternative way will be to add the DataContext line in the Window tag. This way your MainWindow class becomes visible to the view and you can bind to the public properties.

    <Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="{Binding RelativeSource={RelativeSource Self}}"
    Title="MainWindow" Height="350" Width="525">
    

    Now create a public property to access the object:

    Public Property OTime() As TimeUpdate
        Get
            Return oTime
        End Get
        Set
            oTime = value
        End Set
    End Property
    

    And bind the textbox to it:

    <Grid> 
        <TextBox x:Name="myTextBox" 
                 Width="200" Height="50" Foreground="Black" 
                 Text="{Binding Path=OTime.TimeUpdate}"></TextBox>
    </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a WPF application (using C#.net) in which I want
I have made the database using ASP.Net Configuration(aspnet_regsql.exe tool) . I want to use
I'm creating some desktop application using WPF(C# .net). I want to create it as
I am developing an application in C#. I'm using .Net under WPF. I want
I want to use TeeChart (http://www.teechart.net/) ScrollPager tool in my WPF project, but it
I've been using Winforms since .NET 1.1 and I want to start learning WPF.
Using WPF .NET 4.0 in VS2010 RTM: I can't create a fullscreen WPF popup.
I'm using WPF with .NET 3.0. I have a relatively simple DataTemplate defined as
I am looking at differences between using WPF in .NET or using Silverlight 4
I'm using .net WPF geometry classes to graph waveforms. I've been using the matrix

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.