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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:36:59+00:00 2026-05-19T15:36:59+00:00

On a WPF Window, I have a simple listbox of decimal values which have

  • 0

On a WPF Window, I have a simple listbox of decimal values which have an ObservableCollection of Amounts bound to it, a label bound to a Total property that shows the sum of the values below the ListBox, and a TextBox out to the right of the ListBox bound to the selectedItem.Amount property.

When I click on an item in the ListBox I want to be able to edit the selectedItem’s value in the textbox that gets populated, tab off the TextBox, and have the listBoxItem update its value and I want the sum to be updated in the Label as well.

I understand how element-to-element databinding works (i.e. ListBox to Textbox)
What I am having trouble figuring out is element-to-object databinding(i.e. ListBox/ObservableCollection to the Total property)

Thanks so much!

Here are the two simple classes I have so far:

Public Class TransactionModel
Implements INotifyPropertyChanged
'Public Property Amount As Decimal
Private _amount As Decimal
Public Property Amount As Decimal
    Get
        Return _amount
    End Get
    Set(ByVal value As Decimal)
        _amount = value
        OnPropertyChanged(New PropertyChangedEventArgs("Amount"))
    End Set
End Property

Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Public Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
    If Not e Is Nothing Then
        RaiseEvent PropertyChanged(Me, e)
    End If
End Sub

End Class

Public Class ViewModel
Implements INotifyPropertyChanged

Private oc As ObservableCollection(Of TransactionModel)
Sub New()
    oc = New ObservableCollection(Of TransactionModel)
    oc.Add(New TransactionModel With {.Amount = 10.0})
    oc.Add(New TransactionModel With {.Amount = 20.0})
    oc.Add(New TransactionModel With {.Amount = 30.0})
    oc.Add(New TransactionModel With {.Amount = 40.0})
End Sub

Public Function GetAmounts() As ObservableCollection(Of TransactionModel)
    Return oc
End Function

Private _total As Decimal = 0.0
Public Property Total As Decimal
    Get
        For Each o In oc
            _total += o.Amount
        Next
        Return _total
    End Get
    Set(ByVal value As Decimal)
        _total = value
        OnPropertyChanged(New PropertyChangedEventArgs("Total"))
    End Set
End Property

Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Public Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
    If Not e Is Nothing Then
        RaiseEvent PropertyChanged(Me, e)
    End If
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-05-19T15:37:00+00:00Added an answer on May 19, 2026 at 3:37 pm

    The first part is to add a TextBox, and bind it to the SelectedItem property on the ListBox. This will cause the TextBox to show the amount for the selected item, and allow the user to update it’s value:

     <TextBox DataContext="{Binding ElementName=lb1, Path=SelectedItem}"
        Text="{Binding Path=Amount}" />
    

    You will then need a property on ViewModel named TotalAmount, and a TextBlock bound to it’s value. You will also have to handle PropertyChanged for “Value” and re-raise the event for “TotalAmount”, which will cause the View to refresh:

    <TextBlock Text="{Binding Path=TotalAmount}"></TextBlock>
    

    and the event handler:

    Public Class ViewModel Implements INotifyPropertyChanged
        ...
        Public Sub New()
            items = New ObservableCollection(Of TransactionModel)()
            Dim tm As New TransactionModel()
            tm.PropertyChanged += New PropertyChangedEventHandler(TransactionModel_PropertyChanged)
            items.Add(tm)
            tm = New TransactionModel()
            tm.PropertyChanged += New PropertyChangedEventHandler(TransactionModel_PropertyChanged)
            items.Add(tm)
            tm = New TransactionModel()
            tm.PropertyChanged += New PropertyChangedEventHandler(TransactionModel_PropertyChanged)
            items.Add(tm)
        End Sub
    
        Private Sub TransactionModel_PropertyChanged(sender As Object, e As PropertyChangedEventArgs)
            If e.PropertyName = "Amount" Then
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("TotalAmount"))
            End If
        End Sub
        ...
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I have a WPF Window which has a among other controls hosts a Frame.
I have a WPF window for editing database information, which is represented using an
I have a window in WPF which shows some media contents. This content contains
WPF doesn't provide the ability to have a window that allows resize but doesn't
I have a very simple WPF user control that is mixed in with a
I have an observable collection bound to a listbox in WPF. One of the
My Model implements INotifyPropertyChanged , and I have a WPF window bound to it
I created a wpf application which have a single window which is getting started
I have a FlowDocument in a standard WPF application window where I have some

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.