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 3243106
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:23:37+00:00 2026-05-17T18:23:37+00:00

I am quite new to WPF and I am confused about how Data Bindings

  • 0

I am quite new to WPF and I am confused about how Data Bindings should behave.

I have created a class that has 1 property (“status”) and three methods that are responsible for changing the status. This class implements the INotifyPropertyChanged interface so that I am able to notify the calling code when the Status changes.

The class looks like this:

Public Class StreetLight
    Implements System.ComponentModel.INotifyPropertyChanged
    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

    Private _status As String
    Public Property Status As String
        Get
            Return _status
        End Get
        Set(ByVal value As String)
            _status = value
            RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs("Satus"))
        End Set
    End Property
    Public Sub New()
        _status = "unknown"
    End Sub
    Public Sub Red()
        Status = "Red"
    End Sub
    Public Sub Yellow()
        Status = "Yellow"
    End Sub
    Public Sub Green()
        Status = "Green"
    End Sub
End Class

I have created a WPF User Control to represent this class.
This User Control is bound to an instance the StreetLight class. It displays the status of the StreetLight and allows the user to change the status using buttons:

<UserControl x:Class="StreetLightUC"
             x:Name="StreetLightUC"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:twpf="clr-namespace:TryingWPF"
             mc:Ignorable="d" 
             d:DesignHeight="30" d:DesignWidth="360">
    <UserControl.Resources>
        <twpf:StreetLight x:Key="theLight" PropertyChanged="theLight_PropertyChanged" />
    </UserControl.Resources>
    <StackPanel x:Name="StreetLightContent" Orientation="Horizontal">
        <Label Width="100" HorizontalAlignment="Left">Street Light _Status</Label>
        <Label x:Name="streetLightValue" Width="120" HorizontalAlignment="Right" Content="{Binding Path=Status, Mode=OneWay}"></Label>
        <Button x:Name="Red" Click="TurnRed" Width="60">Turn Red</Button>
        <Button x:Name="Green" Click="TurnGreen" Width="60">Turn Green</Button>
    </StackPanel>
</UserControl>

My problem is that even when the status is changed for theLight, it is not updated in the Label that is bound to the Status property unless I create a new StreetLight and set the DataContext to this new instance in the “StreetLight_PropertyChanged” event that handles the PropertyChagned event for the “theLight”

Like so:

Public Class StreetLightUC
    Public Sub New()
        InitializeComponent()
    End Sub
    Private Sub TurnRed(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim light As StreetLight= CType(FindResource("theLight"), StreetLight)
        light.Red()
    End Sub

    Private Sub TurnGreen(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim light As StreetLight = CType(FindResource("theLight"), StreetLight)
        light.Unlock()
    End Sub

    Private Sub theLight_PropertyChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs)
        Dim light As StreetLight = CType(sender, StreetLight )
        Dim newLight As New StreetLight
        newLight.Status = light.Status
        StreetLightContent.DataContext = newLight
    End Sub
End Class

Am I doing something wrong?
It doesn’t seem like I should have to create a new instance of the class to display the updated status-property when this property is change….

Thanks,

-Frinny

  • 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-05-17T18:23:38+00:00Added an answer on May 17, 2026 at 6:23 pm

    You have a typo ("Satus" instead of "Status"):

    RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs("Satus"))
    

    Should be:

    RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs("Status"))
    

    With this typo, the binding doesn’t see that “Status” has changed, and never updates. If you correct this, the PropertyChanged event will correctly reflect that "Status" has changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to WPF data binding. I have a ListBox on a form that
I have a WPF application that uses MVVM data bindings. I am adding items
I am quite new to WPF.I came accross this wonderful project . I have
I'm fairly new to WPF and have since created applications with Win Forms and
I have problem with WPF - I'm quiet new in this smart technology. So
I am quite new to mongoid and rails. So I have some troubles to
I am quite new to WPF and XAML but my background is of ASP.NET
I must say I am quite new at WPF. I am building my first
Hi all i need help wih my combobox. Iam quite new in the WPF
I'm quite new to WPF and as new to Caliburn.Micro. What I'm trying to

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.